Liking cljdoc? Tell your friends :D

toucan2.insert

Implementation of insert!.

The code for building an INSERT query as Honey SQL lives in toucan2.honeysql2

Implementation of [[insert!]].

The code for building an INSERT query as Honey SQL lives in [[toucan2.honeysql2]]
raw docstring

insert!clj

(insert! modelable row-or-rows-or-queryable)
(insert! modelable columns row-vectors)
(insert! :conn connectable modelable row-or-rows)
(insert! modelable k v & more)
(insert! :conn connectable modelable columns row-vectors)
(insert! :conn connectable modelable k v & more)

Insert a row or rows into the database. Returns the number of rows inserted.

This function is pretty flexible in what it accepts:

Insert a single row with key-value args:

(t2/insert! :models/venues :name "Grant & Green", :category "bar")

Insert a single row as a map:

(t2/insert! :models/venues {:name "Grant & Green", :category "bar"})

Insert multiple row maps:

(t2/insert! :models/venues [{:name "Grant & Green", :category "bar"}
                            {:name "Savoy Tivoli", :category "bar"}])

Insert rows with a vector of column names and a vector of value maps:

(t2/insert! :models/venues [:name :category] [["Grant & Green" "bar"]
                                              ["Savoy Tivoli" "bar"]])

As with other Toucan 2 functions, you can optionally pass a connectable if you pass :conn as the first arg. Refer to the :toucan2.insert/args spec for the complete syntax.

Named connectables can also be used to define the rows:

(t2/define-named-query ::named-rows
  {:rows [{:name "Grant & Green", :category "bar"}
          {:name "North Beach Cantina", :category "restaurant"}]})

(t2/insert! :models/venues ::named-rows)
Insert a row or rows into the database. Returns the number of rows inserted.

This function is pretty flexible in what it accepts:

Insert a single row with key-value args:

```clj
(t2/insert! :models/venues :name "Grant & Green", :category "bar")
```

Insert a single row as a map:

```clj
(t2/insert! :models/venues {:name "Grant & Green", :category "bar"})
```

Insert multiple row maps:

```clj
(t2/insert! :models/venues [{:name "Grant & Green", :category "bar"}
                            {:name "Savoy Tivoli", :category "bar"}])
```

Insert rows with a vector of column names and a vector of value maps:

```clj
(t2/insert! :models/venues [:name :category] [["Grant & Green" "bar"]
                                              ["Savoy Tivoli" "bar"]])
```

As with other Toucan 2 functions, you can optionally pass a connectable if you pass `:conn` as the first arg. Refer to
the `:toucan2.insert/args` spec for the complete syntax.

Named connectables can also be used to define the rows:

```clj
(t2/define-named-query ::named-rows
  {:rows [{:name "Grant & Green", :category "bar"}
          {:name "North Beach Cantina", :category "restaurant"}]})

(t2/insert! :models/venues ::named-rows)
```
sourceraw docstring

insert-returning-instance!clj

(insert-returning-instance! modelable row-or-rows-or-queryable)
(insert-returning-instance! modelable columns row-vectors)
(insert-returning-instance! :conn connectable modelable row-or-rows)
(insert-returning-instance! modelable k v & more)
(insert-returning-instance! :conn connectable modelable columns row-vectors)
(insert-returning-instance! :conn connectable modelable k v & more)

Like insert-returning-instances!, but for one-row insertions. Returns the inserted object as a map.

Like [[insert-returning-instances!]], but for one-row insertions. Returns the inserted object as a map.
sourceraw docstring

insert-returning-instances!clj

(insert-returning-instances! modelable-columns row-or-rows-or-queryable)
(insert-returning-instances! modelable-columns columns row-vectors)
(insert-returning-instances! :conn connectable modelable-columns row-or-rows)
(insert-returning-instances! modelable-columns k v & more)
(insert-returning-instances! :conn
                             connectable
                             modelable-columns
                             columns
                             row-vectors)
(insert-returning-instances! :conn connectable modelable-columns k v & more)

Like insert!, but returns a vector of maps representing the inserted objects.

Like [[insert!]], but returns a vector of maps representing the inserted objects.
sourceraw docstring

insert-returning-pk!clj

(insert-returning-pk! modelable row-or-rows-or-queryable)
(insert-returning-pk! modelable columns row-vectors)
(insert-returning-pk! :conn connectable modelable row-or-rows)
(insert-returning-pk! modelable k v & more)
(insert-returning-pk! :conn connectable modelable columns row-vectors)
(insert-returning-pk! :conn connectable modelable k v & more)

Like insert-returning-pks!, but for one-row insertions. For models with a single primary key, this returns just the new primary key as a scalar value (e.g. 1). For models with a composite primary key, it will return a single tuple as determined by model/primary-keys (e.g. [1 "Cam"]).

Like [[insert-returning-pks!]], but for one-row insertions. For models with a single primary key, this returns just the
new primary key as a scalar value (e.g. `1`). For models with a composite primary key, it will return a single tuple
as determined by [[model/primary-keys]] (e.g. `[1 "Cam"]`).
sourceraw docstring

insert-returning-pks!clj

(insert-returning-pks! modelable row-or-rows-or-queryable)
(insert-returning-pks! modelable columns row-vectors)
(insert-returning-pks! :conn connectable modelable row-or-rows)
(insert-returning-pks! modelable k v & more)
(insert-returning-pks! :conn connectable modelable columns row-vectors)
(insert-returning-pks! :conn connectable modelable k v & more)

Like insert!, but returns a vector of the primary keys of the newly inserted rows rather than the number of rows inserted. The primary keys are determined by model/primary-keys. For models with a single primary key, this returns a vector of single values, e.g. [1 2] if the primary key is :id and you've inserted rows 1 and 2; for composite primary keys this returns a vector of tuples where each tuple has the value of corresponding primary key as returned by model/primary-keys, e.g. for composite PK [:id :name] you might get [[1 "Cam"] [2 "Sam"]].

Like [[insert!]], but returns a vector of the primary keys of the newly inserted rows rather than the number of rows
inserted. The primary keys are determined by [[model/primary-keys]]. For models with a single primary key, this
returns a vector of single values, e.g. `[1 2]` if the primary key is `:id` and you've inserted rows 1 and 2; for
composite primary keys this returns a vector of tuples where each tuple has the value of corresponding primary key as
returned by [[model/primary-keys]], e.g. for composite PK `[:id :name]` you might get `[[1 "Cam"] [2 "Sam"]]`.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close