Liking cljdoc? Tell your friends :D

toucan2.execute

Code for executing queries and statements, and reducing their results.

The functions here meant for use on a regular basis are:

  • query -- resolve and compile a connectable, execute it using a connection from a connectable, and immediately fully realize the results.

  • query-one -- like query, but only realizes the first result.

  • reducible-query -- like query, but returns a [[clojure.lang.IReduceInit]] that can be reduced later rather than immediately realizing the results.

  • with-call-count -- helper macro to count the number of queries executed within a body.

Code for executing queries and statements, and reducing their results.

The functions here meant for use on a regular basis are:

* [[query]] -- resolve and compile a connectable, execute it using a connection from a connectable, and immediately
               fully realize the results.

* [[query-one]] -- like [[query]], but only realizes the first result.

* [[reducible-query]] -- like [[query]], but returns a [[clojure.lang.IReduceInit]] that can be reduced later rather
  than immediately realizing the results.

* [[with-call-count]] -- helper macro to count the number of queries executed within a `body`.
raw docstring

queryclj

(query queryable)
(query connectable queryable)
(query connectable modelable queryable)
(query connectable query-type modelable queryable)

Like reducible-query, but immediately executes and fully reduces the query.

(query ::my-connectable ["SELECT * FROM venues;"])
;; => [{:id 1, :name "Tempest"}
       {:id 2, :name "BevMo"}]

Like reducible-query, this may be used with either SELECT queries that return rows or things like UPDATE that normally return the count of rows updated.

Like [[reducible-query]], but immediately executes and fully reduces the query.

```clj
(query ::my-connectable ["SELECT * FROM venues;"])
;; => [{:id 1, :name "Tempest"}
       {:id 2, :name "BevMo"}]
```

Like [[reducible-query]], this may be used with either `SELECT` queries that return rows or things like `UPDATE` that
normally return the count of rows updated.
sourceraw docstring

query-oneclj

(query-one queryable)
(query-one connectable queryable)
(query-one connectable modelable queryable)
(query-one connectable query-type modelable queryable)

Like query, and immediately executes the query, but realizes and returns only the first result.

(query-one ::my-connectable ["SELECT * FROM venues;"])
;; => {:id 1, :name "Tempest"}

Like reducible-query, this may be used with either SELECT queries that return rows or things like UPDATE that normally return the count of rows updated.

Like [[query]], and immediately executes the query, but realizes and returns only the first result.

```clj
(query-one ::my-connectable ["SELECT * FROM venues;"])
;; => {:id 1, :name "Tempest"}
```

Like [[reducible-query]], this may be used with either `SELECT` queries that return rows or things like `UPDATE` that
normally return the count of rows updated.
sourceraw docstring

reducible-queryclj

(reducible-query queryable)
(reducible-query connectable queryable)
(reducible-query connectable modelable queryable)
(reducible-query connectable query-type modelable queryable)

Create a reducible query that when reduced with resolve and compile queryable, open a connection using connectable and toucan2.connection/with-connection, execute the query, and reduce the results.

Note that this query can be something like a SELECT query, or something that doesn't normally return results, like an UPDATE; this works either way. Normally something like an UPDATE will reduce to the number of rows updated/inserted/deleted, e.g. [5].

You can specify modelable to execute the query in the context of a specific model; for queries returning rows, the rows will be returned as an toucan2.instance/instance of the resolved model.

See toucan2.connection for Connection resolution rules.

Create a reducible query that when reduced with resolve and compile `queryable`, open a connection using `connectable`
and [[toucan2.connection/with-connection]], execute the query, and reduce the results.

Note that this query can be something like a `SELECT` query, or something that doesn't normally return results, like
an `UPDATE`; this works either way. Normally something like an `UPDATE` will reduce to the number of rows
updated/inserted/deleted, e.g. `[5]`.

You can specify `modelable` to execute the query in the context of a specific model; for queries returning rows, the
rows will be returned as an [[toucan2.instance/instance]] of the resolved model.

See [[toucan2.connection]] for Connection resolution rules.
sourceraw docstring

with-call-countcljmacro

(with-call-count [call-count-fn-binding] & body)

Execute body, trackingthe number of database queries and statements executed. This number can be fetched at any time withing body by calling function bound to call-count-fn-binding:

(with-call-count [call-count]
  (select ...)
  (println "CALLS:" (call-count))
  (insert! ...)
  (println "CALLS:" (call-count)))
;; -> CALLS: 1
;; -> CALLS: 2
Execute `body`, trackingthe number of database queries and statements executed. This number can be fetched at any
time withing `body` by calling function bound to `call-count-fn-binding`:

```clj
(with-call-count [call-count]
  (select ...)
  (println "CALLS:" (call-count))
  (insert! ...)
  (println "CALLS:" (call-count)))
;; -> CALLS: 1
;; -> CALLS: 2
```
sourceraw docstring

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

× close