Liking cljdoc? Tell your friends :D

io.randomseed.utils.db.coercion

Random Utilities, databases coercers.

Random Utilities, databases coercers.
raw docstring

->clj

(-> table-column v)
(-> table column v)

Coerces value v from a database type by calling a function returned by invoking io.randomseed.utils.db/out-coercer multimethod on a qualified keyword table-column (or a qualified keyword made out of table and column). If there is no coercer attached for the keyword, returns unchanged v.

If a coercer can be obtained at compile-time, a coercion function-call form will be generated. If a coercer can be obtained at compile-time and the given value is statically convertable, value resulting from applying coercion function will be generated immediately.

Coerces value `v` from a database type by calling a function returned by invoking
`io.randomseed.utils.db/out-coercer` multimethod on a qualified keyword `table-column` (or a
qualified keyword made out of `table` and `column`). If there is no coercer
attached for the keyword, returns unchanged `v`.

If a coercer can be obtained at compile-time, a coercion function-call form will be
generated. If a coercer can be obtained at compile-time and the given value is
statically convertable, value resulting from applying coercion function will be
generated immediately.
sourceraw docstring

<-cljmacro

(<- table-column v)
(<- table column v)

Coerces value v to a database type by calling a function returned by invoking io.randomseed.utils.db/in-coercer multimethod on a qualified keyword table-column (or a qualified keyword made out of table and column). If there is no coercer attached for the keyword, returns unchanged v.

If a coercer can be obtained at compile-time, a coercion function-call form will be generated. If a coercer can be obtained at compile-time and the given value is statically convertable, value resulting from applying coercion function will be generated immediately.

Coerces value `v` to a database type by calling a function returned by invoking
`io.randomseed.utils.db/in-coercer` multimethod on a qualified keyword `table-column` (or a
qualified keyword made out of `table` and `column`). If there is no coercer
attached for the keyword, returns unchanged `v`.

If a coercer can be obtained at compile-time, a coercion function-call form will be
generated. If a coercer can be obtained at compile-time and the given value is
statically convertable, value resulting from applying coercion function will be
generated immediately.
sourceraw docstring

<-seqcljmacro

(<-seq table-column coll)
(<-seq table column coll)

Coerces a sequence of values coll to database types by calling a function returned by invoking io.randomseed.utils.db/in-coercer multimethod on a qualified keyword table-column (or a qualified keyword made out of table and column). If there is no coercer attached for the keyword, returns unchanged coll.

If both, a table and a column can be used to establish coercion function at compile-time, a mapping form will be generated which uses that function.

Coerces a sequence of values `coll` to database types by calling a function returned
by invoking `io.randomseed.utils.db/in-coercer` multimethod on a qualified keyword
`table-column` (or a qualified keyword made out of `table` and `column`). If there
is no coercer attached for the keyword, returns unchanged `coll`.

If both, a table and a column can be used to establish coercion function at
compile-time, a mapping form will be generated which uses that function.
sourceraw docstring

<<-cljmacro

(<<- & specs)

Magical macro which converts a sequence of values with optional table and column specifications to a database-suitable formats. Pre-processing of arguments is executed at compile-time, further processing is performed at run-time.

Any type of argument is accepted but literal vectors, including nested vectors, are control structures. Their first elements are table names (for the first one), column names (for nested vectors) or both (when expressed using fully-qualified keywords).

Example: (<<- 1 2 3 [:table-name [:column-name :val1 val2 (exp3) "val4"])

1, 2 and 3 are regular values, :table-name is literally expressed table name for coercer, :column-name is literally expressed column name for coercer, other expressions are values to be coerced. Table and column names can be dynamic, expressed with symbols or call forms.

All macro arguments are sequentially transformed with the following rules:

  • If there is a literal vector at 1st level, its first element should be a table name. All elements of that vector will inherit that table name during conversion to a database-suitable format.

  • If there is a literal vector nested within existing vector its first element will be considered a column name. All elements of that vector will inherit that column name during conversion to a database-suitable format.

  • If the given literal vector contains a fully-qualified keyword at its first position then both table and column will be memorized to be applied during conversion of elements contained in that vector (table taken from a namespace and column from a name of the keyword).

  • If there is a table name inherited but no column specified, a value is not converted but returned as is, with the exception: when the value is expressed as a literal, simple symbol then a column name will be derived from its name.

  • A sub-vector may begin with an unspecified value nil. In such case it will group values to be converted but column name will not be set. The values will be left unconverted unless they are simple symbol forms; in such case column names will be derived from their names.

Values used to set column and table names at the beginnings of vectors can be expressed with any valid code. However, literal strings or literal keywords (or symbols in case of identifier-derived column names) will be pre-processed at compile time. So, if both column and table name are expressed that way, the conversion specifier will be generated ahead.

Moreover, if apart from the above, a value to be coerced is expressed as a literal number, string, keyword, boolean, or a nil, it will be converted at compile-time.

Conversion of repeating atomic expressions sharing the same table and column name identifiers (including symbolic identifiers) will be performed in ad-hoc created let block, and the results will be referenced using auto-generated symbols replacing the original expressions. Therefore, conversion for repeated symbols (and other atomic expressions) will be performed just once.

Examples:

(<<- [:users [:id id] [:email email]])

The above will convert values expressed by id and email symbol forms using a variant of coercion multimethod registered for :users/id and :users/email keywords, accordingly.

(<<- [:users/id id [:email e]])

The above will convert values of id and e symbol forms using a variant of coercion multimethod registered for :users/id and :users/email keywords, accordingly.

(<<- [:users [:id id] [:confirmations/email email [:expires expires]])

The above will convert values of id, email and expires symbol forms using a variant of coercion multimethod registered for :users/id, :confirmations/email, and :confirmations/expires keywords, accordingly. We can see that second vector changes the table name to confirmations in its scope so later expires derives it and is converted with :confirmations/expires specification.

This is synonymous to:

(<<- [:users id] [:confirmations email expires])

As we can see, the id symbolic identifier is used to set the column name, same as email and expires symbols. The above code will be expanded to:

[(io.randomseed.utils.db/<- :users/id id)
 (io.randomseed.utils.db/<- :confirmations/email email)
 (io.randomseed.utils.db/<- :confirmations/expires expires)]

And then to:

[(#<Fn@4d7e49d myapp.model.user/id_to_db> id)
 (io.randomseed.utils.db/coerce-in* :confirmations/email email)
 (#<Fn@3bf6fdc6 myapp.model.confirmation/to_expiry> expires)]

We can see that coercers for id and expires symbols were resolved and function call forms were created at compile-time. That's because :users/id and :confirmations/expires were recognized as existing dispatch values when calling in-coercer internally. A coercer for the email symbol (using :confirmations/email dispatch value) was not recognized at compile-time so the call to io.randomseed.utils.db/coerce-in* was generated instead.

Let's have a quick look at some real-world example:

(io.randomseed.utils.db/<<-  [:confirmations id code token reason id-type expires id id])

And generated Clojure code (phase 1):

(let [DB__confirmations_id_id_54377141 (io.randomseed.utils.db/<- :confirmations/id id)]
  [DB__confirmations_id_id_54377141
   (io.randomseed.utils.db/<- :confirmations/code       code)
   (io.randomseed.utils.db/<- :confirmations/token     token)
   (io.randomseed.utils.db/<- :confirmations/reason   reason)
   (io.randomseed.utils.db/<- :confirmations/id-type id-type)
   (io.randomseed.utils.db/<- :confirmations/expires expires)
   DB__confirmations_id_id_54377141
   DB__confirmations_id_id_54377141])

And fully expanded:

(let* [DB__confirmations_id_id_54377141 (#<Fn@5a424a5a io.randomseed.utils.identity/__GT_db> id)]
  [DB__confirmations_id_id_54377141
   (#<Fn@279d4dd9 io.randomseed.utils/safe_parse_long>       code)
   (#<Fn@7f1abd95 io.randomseed.utils/some_str>             token)
   (#<Fn@7f1abd95 io.randomseed.utils/some_str>            reason)
   (#<Fn@7f1abd95 io.randomseed.utils/some_str>           id-type)
   (#<Fn@4ac5d426 myapp.model.confirmation/to_expiry> expires)
   DB__confirmations_id_id_54377141
   DB__confirmations_id_id_54377141])

A SQL query which uses the sequence of values presented above needs one of them (identified with the id) to be repeated. We can observe that the macro generated let binding for it to assign the result of calling io.randomseed.utils.identity/->db on id to auto-generated symbol named DB__confirmations_id_id_54377141. This symbol is then re-used in output vector multiple times so the calculation is performed just once.

Also, other coercers were successfully resolved to function objects during macro expansion since we have static table and column specifiers given.

Rule of a thumb is: if you can express certain values or specifications with literal strings or keywords, it may speed things up.

Magical macro which converts a sequence of values with optional table and column
specifications to a database-suitable formats. Pre-processing of arguments is
executed at compile-time, further processing is performed at run-time.

Any type of argument is accepted but literal vectors, including nested vectors, are
**control structures**. Their first elements are table names (for the first one),
column names (for nested vectors) or both (when expressed using fully-qualified
keywords).

Example: `(<<- 1 2 3 [:table-name [:column-name :val1 val2 (exp3) "val4"])`

`1`, `2` and `3` are regular values, `:table-name` is literally expressed table
name for coercer, `:column-name` is literally expressed column name for coercer,
other expressions are values to be coerced. Table and column names can be dynamic,
expressed with symbols or call forms.

All macro arguments are sequentially transformed with the following rules:

- If there is a **literal vector** at **1st level**, its first element should be a
table name. All elements of that vector will inherit that table name during
conversion to a database-suitable format.

- If there is a **literal vector** nested within existing vector its first element
will be considered a **column name**. All elements of that vector will inherit that
column name during conversion to a database-suitable format.

- If the given literal vector contains a **fully-qualified keyword** at its first
position then both **table** and **column** will be memorized to be applied during
conversion of elements contained in that vector (table taken from a namespace and
column from a name of the keyword).

- If there is a table name inherited but no column specified, a value is not
converted but returned as is, with the exception: when the value is expressed as a
**literal, simple symbol** then a column name will be derived from its name.

- A sub-vector may begin with an unspecified value `nil`. In such case it will
group values to be converted but column name will not be set. The values will be
left unconverted unless they are simple symbol forms; in such case column names
will be derived from their names.

Values used to set column and table names at the beginnings of vectors can be
expressed with any valid code. However, literal strings or literal keywords (or
symbols in case of identifier-derived column names) will be pre-processed at
compile time. So, if both column and table name are expressed that way, the
conversion specifier will be generated ahead.

Moreover, if apart from the above, a value to be coerced is expressed as a literal
number, string, keyword, boolean, or a `nil`, it will be converted at compile-time.

Conversion of repeating atomic expressions sharing the same table and column name
identifiers (including symbolic identifiers) will be performed in ad-hoc created
`let` block, and the results will be referenced using auto-generated symbols
replacing the original expressions. Therefore, conversion for repeated symbols (and
other atomic expressions) will be performed just once.

Examples:

`(<<- [:users [:id id] [:email email]])`

The above will convert values expressed by `id` and `email` symbol forms using a
variant of coercion multimethod registered for `:users/id` and `:users/email`
keywords, accordingly.

`(<<- [:users/id id [:email e]])`

The above will convert values of `id` and `e` symbol forms using a variant of
coercion multimethod registered for `:users/id` and `:users/email` keywords,
accordingly.

`(<<- [:users [:id id] [:confirmations/email email [:expires expires]])`

The above will convert values of `id`, `email` and `expires` symbol forms using a
variant of coercion multimethod registered for `:users/id`, `:confirmations/email`,
and `:confirmations/expires` keywords, accordingly. We can see that second vector
changes the table name to `confirmations` in its scope so later `expires` derives
it and is converted with `:confirmations/expires` specification.

This is synonymous to:

`(<<- [:users id] [:confirmations email expires])`

As we can see, the `id` symbolic identifier is used to set the column name, same as
`email` and `expires` symbols. The above code will be expanded to:

```
[(io.randomseed.utils.db/<- :users/id id)
 (io.randomseed.utils.db/<- :confirmations/email email)
 (io.randomseed.utils.db/<- :confirmations/expires expires)]
```

And then to:

```
[(#<Fn@4d7e49d myapp.model.user/id_to_db> id)
 (io.randomseed.utils.db/coerce-in* :confirmations/email email)
 (#<Fn@3bf6fdc6 myapp.model.confirmation/to_expiry> expires)]
```

We can see that coercers for `id` and `expires` symbols were resolved and function
call forms were created at compile-time. That's because `:users/id` and
`:confirmations/expires` were recognized as existing dispatch values when calling
`in-coercer` internally. A coercer for the `email` symbol (using
`:confirmations/email` dispatch value) was not recognized at compile-time so
the call to `io.randomseed.utils.db/coerce-in*` was generated instead.

Let's have a quick look at some real-world example:

```
(io.randomseed.utils.db/<<-  [:confirmations id code token reason id-type expires id id])
```

And generated Clojure code (phase 1):

```
(let [DB__confirmations_id_id_54377141 (io.randomseed.utils.db/<- :confirmations/id id)]
  [DB__confirmations_id_id_54377141
   (io.randomseed.utils.db/<- :confirmations/code       code)
   (io.randomseed.utils.db/<- :confirmations/token     token)
   (io.randomseed.utils.db/<- :confirmations/reason   reason)
   (io.randomseed.utils.db/<- :confirmations/id-type id-type)
   (io.randomseed.utils.db/<- :confirmations/expires expires)
   DB__confirmations_id_id_54377141
   DB__confirmations_id_id_54377141])
```

And fully expanded:

```
(let* [DB__confirmations_id_id_54377141 (#<Fn@5a424a5a io.randomseed.utils.identity/__GT_db> id)]
  [DB__confirmations_id_id_54377141
   (#<Fn@279d4dd9 io.randomseed.utils/safe_parse_long>       code)
   (#<Fn@7f1abd95 io.randomseed.utils/some_str>             token)
   (#<Fn@7f1abd95 io.randomseed.utils/some_str>            reason)
   (#<Fn@7f1abd95 io.randomseed.utils/some_str>           id-type)
   (#<Fn@4ac5d426 myapp.model.confirmation/to_expiry> expires)
   DB__confirmations_id_id_54377141
   DB__confirmations_id_id_54377141])
```

A SQL query which uses the sequence of values presented above needs one of
them (identified with the `id`) to be repeated. We can observe that the macro
generated `let` binding for it to assign the result of calling
`io.randomseed.utils.identity/->db` on `id` to auto-generated symbol named
`DB__confirmations_id_id_54377141`. This symbol is then re-used in output vector
multiple times so the calculation is performed just once.

Also, other coercers were successfully resolved to function objects during macro
expansion since we have static table and column specifiers given.

Rule of a thumb is: if you can express certain values or specifications with
literal strings or keywords, it may speed things up.
sourceraw docstring

<<-*cljmacro

(<<-* spec)
(<<-* spec & specs)

Same as <<- but its last argument should be a sequence to be concatenated with the results without any pre-processing.

Same as `<<-` but its last argument should be a sequence to be concatenated with the
results without any pre-processing.
sourceraw docstring

<d-do!cljmacro

(<d-do! f db query & params)

Calls function f, passing db as a first argument and a sequence of:

  • a query (being a result of transforming query with io.randomseed.utils.db.sql/build-query-dynamic),
  • coerced parameters (being a result of transforming params with <<-).
Calls function `f`, passing `db` as a first argument and a sequence of:
- a query (being a result of transforming `query` with `io.randomseed.utils.db.sql/build-query-dynamic`),
- coerced parameters (being a result of transforming `params` with `<<-`).
sourceraw docstring

<d-exec!cljmacro

(<d-exec! db query & params)

Calls execute!, passing db as a first argument and a sequence of:

  • a query (being a result of transforming query with io.randomseed.utils.db.sql/build-query-dynamic),
  • coerced parameters (being a result of transforming params with <<-).
Calls `execute!`, passing `db` as a first argument and a sequence of:
- a query (being a result of transforming `query` with `io.randomseed.utils.db.sql/build-query-dynamic`),
- coerced parameters (being a result of transforming `params` with `<<-`).
sourceraw docstring

<d-exec-one!cljmacro

(<d-exec-one! db query & params)

Calls execute-one!, passing db as a first argument and a sequence of:

  • a query (being a result of transforming query with io.randomseed.utils.db.sql/build-query-dynamic),
  • coerced parameters (being a result of transforming params with <<-).
Calls `execute-one!`, passing `db` as a first argument and a sequence of:
- a query (being a result of transforming `query` with `io.randomseed.utils.db.sql/build-query-dynamic`),
- coerced parameters (being a result of transforming `params` with `<<-`).
sourceraw docstring

<do!cljmacro

(<do! f db query & params)

Calls function f passing db as a first argument and a sequence of:

  • a query (being a result of transforming query with io.randomseed.utils.db.sql/build-query),
  • coerced parameters (being a result of transforming params with <<-).
Calls function `f` passing `db` as a first argument and a sequence of:
- a query (being a result of transforming `query` with `io.randomseed.utils.db.sql/build-query`),
- coerced parameters (being a result of transforming `params` with `<<-`).
sourceraw docstring

<dqcljmacro

(<dq query & params)

Simple wrapper around io.randomseed.utils.db.sql/build-query-dynamic and <<- macros. First argument should be a query (possibly grouped with a vector, if multiple arguments need to be passed), all other arguments are passed to <<-.

Produces a sequence suitable to be used with execute-* family of functions (a parameterized query as its first element and coerced query parameters as other elements).

Intended to be used for dynamically generated database queries. Uses a bit slower but safer FIFO cache of default size (about 150k items).

Example:

(<q ["select %(id) from %[u] where %(id) = ? AND %(t) = ?"
     {:id :users/id, :u :users/id, :t :users/account-type}]
    [:users [:id "42"] [:account-type :user]])

The above will return:

("select `id` from `users` where `id` = ? AND `account_type` = ?" 42 "user")

Note that "42" and :user are values which are to be coerced (first with a coercer registered for :users/id and second with a coercer registered for :users/account-type). After the coercion resulting values (42 and "user") are placed in a sequence to become query parameters.

Simple wrapper around `io.randomseed.utils.db.sql/build-query-dynamic` and `<<-` macros. First
argument should be a query (possibly grouped with a vector, if multiple arguments
need to be passed), all other arguments are passed to `<<-`.

Produces a sequence suitable to be used with `execute-*` family of functions (a
parameterized query as its first element and coerced query parameters as other
elements).

Intended to be used for dynamically generated database queries. Uses a bit slower
but safer FIFO cache of default size (about 150k items).

Example:

```
(<q ["select %(id) from %[u] where %(id) = ? AND %(t) = ?"
     {:id :users/id, :u :users/id, :t :users/account-type}]
    [:users [:id "42"] [:account-type :user]])
```

The above will return:

```
("select `id` from `users` where `id` = ? AND `account_type` = ?" 42 "user")
```

Note that `"42"` and `:user` are values which are to be coerced (first with a
coercer registered for `:users/id` and second with a coercer registered for
`:users/account-type`). After the coercion resulting values (`42` and `"user"`)
are placed in a sequence to become query parameters.
sourceraw docstring

<exec!cljmacro

(<exec! db query & params)

Calls execute!, passing db as a first argument and a sequence of:

  • a query (being a result of transforming query with io.randomseed.utils.db.sql/build-query),
  • coerced parameters (being a result of transforming params with <<-).
Calls `execute!`, passing `db` as a first argument and a sequence of:
- a query (being a result of transforming `query` with `io.randomseed.utils.db.sql/build-query`),
- coerced parameters (being a result of transforming `params` with `<<-`).
sourceraw docstring

<exec-one!cljmacro

(<exec-one! db query & params)

Calls execute-one!, passing db as a first argument and a sequence of:

  • a query (being a result of transforming query with io.randomseed.utils.db.sql/build-query),
  • coerced parameters (being a result of transforming params with <<-).
Calls `execute-one!`, passing `db` as a first argument and a sequence of:
- a query (being a result of transforming `query` with `io.randomseed.utils.db.sql/build-query`),
- coerced parameters (being a result of transforming `params` with `<<-`).
sourceraw docstring

<qcljmacro

(<q query & params)

Simple wrapper around io.randomseed.utils.db.sql/build-query and <<- macros. First argument should be a query (possibly grouped with a vector, if multiple arguments need to be passed), all other arguments are passed to <<-.

Produces a sequence suitable to be used with execute-* family of functions (a parameterized query as its first element and coerced query parameters as other elements).

Example:

(<q ["select %(id) from %[u] where %(id) = ? AND %(t) = ?"
     {:id :users/id, :u :users/id, :t :users/account-type}]
    [:users [:id "42" :account-type :user]])

The above will return:

("select `id` from `users` where `id` = ? AND `account_type` = ?" 42 "user")

Note that "42" and :user are values which are to be coerced (first with a coercer registered for :users/id and second with a coercer registered for :users/account-type). After the coercion resulting values (42 and "user") are placed in a sequence to become query parameters.

Simple wrapper around `io.randomseed.utils.db.sql/build-query` and `<<-` macros. First
argument should be a query (possibly grouped with a vector, if multiple arguments
need to be passed), all other arguments are passed to `<<-`.

Produces a sequence suitable to be used with `execute-*` family of functions (a
parameterized query as its first element and coerced query parameters as other
elements).

Example:

```
(<q ["select %(id) from %[u] where %(id) = ? AND %(t) = ?"
     {:id :users/id, :u :users/id, :t :users/account-type}]
    [:users [:id "42" :account-type :user]])
```

The above will return:

```
("select `id` from `users` where `id` = ? AND `account_type` = ?" 42 "user")
```

Note that `"42"` and `:user` are values which are to be coerced (first with a
coercer registered for `:users/id` and second with a coercer registered for
`:users/account-type`). After the coercion resulting values (`42` and `"user"`)
are placed in a sequence to become query parameters.
sourceraw docstring

bindable-symclj

(bindable-sym bindings qs v)

Returns a bindable, auto-generated symbol for the table/column (from qs, which should be a QSlot record) and a value v. The unique identifier (obtained using gen-qs-keyword) must exists in bindings map. Otherwise, nil is returned.

Returns a bindable, auto-generated symbol for the table/column (from `qs`, which
should be a `QSlot` record) and a value `v`. The unique identifier (obtained using
`gen-qs-keyword`) must exists in `bindings` map. Otherwise, `nil` is returned.
sourceraw docstring

bindable-sym?clj

(bindable-sym? bindings qs v)

Returns true if a bindable, auto-generated symbol for the table/column (from qs, which should be a QSlot record) and a value v exist in bindings map. Otherwise it returns false.

Returns `true` if a bindable, auto-generated symbol for the table/column (from `qs`,
which should be a `QSlot` record) and a value `v` exist in `bindings` map. Otherwise
it returns `false`.
sourceraw docstring

cache-createclj

(cache-create ttl)
(cache-create ttl queue-size)
(cache-create ttl queue-size initial-map)

Creates a cache object of the given TTL and/or queue size. Optionally it can get an initial map of entries. Returns cache object encapsulated in an atom.

Creates a cache object of the given TTL and/or queue size. Optionally it can get an
initial map of entries. Returns cache object encapsulated in an atom.
sourceraw docstring

cache-evict!clj

(cache-evict! cache-atom entry)
(cache-evict! cache-atom entry & more)

Removes entry or entries from the cache. Returns the updated cache from the atom.

Removes entry or entries from the cache. Returns the updated cache from the atom.
sourceraw docstring

cache-lookupclj

(cache-lookup cache id)
(cache-lookup cache id & ids)

Looks for the entry of the given ID in a cache which should be a cache object encapsulated in an atom. For multiple IDs, calls cache-lookup-coll. If the entry was not found, returns :io.randomseed.utils.db/not-found.

Looks for the entry of the given ID in a cache which should be a cache object
encapsulated in an atom. For multiple IDs, calls `cache-lookup-coll`. If the entry
was not found, returns `:io.randomseed.utils.db/not-found`.
sourceraw docstring

cache-lookup-collclj

(cache-lookup-coll cache ids)

Looks for a collection of entries identified by the given ID in a cache which should be a cache object encapsulated in an atom. Returns a map with identifiers as keys and values for all found entries. Entries which are missing in the cache are grouped under the :io.randomseed.utils.db/not-found key as a list.

Looks for a collection of entries identified by the given ID in a cache which should
be a cache object encapsulated in an atom. Returns a map with identifiers as keys
and values for all found entries. Entries which are missing in the cache are
grouped under the `:io.randomseed.utils.db/not-found` key as a list.
sourceraw docstring

cache-prepareclj

(cache-prepare ttl)
(cache-prepare ttl queue-size)
(cache-prepare ttl queue-size initial-map)

Prepares a cache object of the given TTL and/or queue size. Optionally it can be populated with an initial map of entries. Returns a cache object.

Prepares a cache object of the given TTL and/or queue size. Optionally it can be
populated with an initial map of entries. Returns a cache object.
sourceraw docstring

coerce-inclj

(coerce-in table-column v)
(coerce-in table column v)

Coerces the given value v to a database type by calling a function returned by invoking io.randomseed.utils.db/in-coercer multimethod on a qualified keyword table-column (or a qualified keyword made out of table and column). If there is no coercer attached for the keyword, tries with a keyword created using the column-kw function. If there is no coercer, returns unchanged v.

Will immediately return the given value v if the coercer exists but it is set to false.

Coerces the given value `v` to a database type by calling a function returned by
invoking `io.randomseed.utils.db/in-coercer` multimethod on a qualified keyword
`table-column` (or a qualified keyword made out of `table` and `column`). If there
is no coercer attached for the keyword, tries with a keyword created using the
`column-kw` function. If there is no coercer, returns unchanged `v`.

Will immediately return the given value `v` if the coercer exists but it is set to
`false`.
sourceraw docstring

coerce-in*clj

(coerce-in* table-column v)

Same as coerce-in but table-column must be a lisp-cased keyword (already a result of colspec-kw or column-kw).

Same as `coerce-in` but `table-column` must be a lisp-cased keyword (already a
result of `colspec-kw` or `column-kw`).
sourceraw docstring

coerce-outclj

(coerce-out table-column v)
(coerce-out table column v)

Coerces the given value v from a database type by calling a function returned by invoking io.randomseed.utils.db/out-coercer multimethod on a qualified keyword table-column (or a qualified keyword made out of table and column). If there is no coercer attached for the keyword, tries with a keyword created using the column-kw function (to use column alone). If there is no coercer, returns unchanged v.

Will immediately return the given value v if the coercer exists but it is set to false.

Coerces the given value `v` from a database type by calling a function returned by
invoking `io.randomseed.utils.db/out-coercer` multimethod on a qualified keyword
`table-column` (or a qualified keyword made out of `table` and `column`). If there
is no coercer attached for the keyword, tries with a keyword created using the
`column-kw` function (to use column alone). If there is no coercer, returns
unchanged `v`.

Will immediately return the given value `v` if the coercer exists but it is
set to `false`.
sourceraw docstring

coerce-out*clj

(coerce-out* table-column v)

Same as coerce-out but table-column must be a lisp-cased keyword (already a result of colspec-kw or column-kw).

Same as `coerce-out` but `table-column` must be a lisp-cased keyword (already a
result of `colspec-kw` or `column-kw`).
sourceraw docstring

coerce-seq-inclj

(coerce-seq-in table-column coll)
(coerce-seq-in table column coll)

Coerces a sequence of values coll to database types by calling a function returned by invoking io.randomseed.utils.db/in-coercer multimethod on a qualified keyword table-column (or a qualified keyword made out of table and column). If there is no coercer attached for the keyword, tries with a keyword created using the column-kw function (to use column alone). If there is no coercer, returns unchanged coll.

Coerces a sequence of values `coll` to database types by calling a function returned
by invoking `io.randomseed.utils.db/in-coercer` multimethod on a qualified keyword
`table-column` (or a qualified keyword made out of `table` and `column`). If there
is no coercer attached for the keyword, tries with a keyword created using the
`column-kw` function (to use column alone). If there is no coercer, returns
unchanged `coll`.
sourceraw docstring

coerce-seq-in*clj

(coerce-seq-in* table-column coll)

Same as coerce-seq-in but table-column must be a lisp-cased keyword (already a result of colspec-kw or column-kw).

Same as `coerce-seq-in` but `table-column` must be a lisp-cased keyword (already a
result of `colspec-kw` or `column-kw`).
sourceraw docstring

coerce-seq-outclj

(coerce-seq-out table-column coll)
(coerce-seq-out table column coll)

Coerces a sequence of values coll from database types by calling a function returned by invoking io.randomseed.utils.db/out-coercer multimethod on a qualified keyword table-column (or a qualified keyword made out of table and column). If there is no coercer attached for the keyword, tries with a keyword created using the column-kw function (to use column alone). If there is no coercer, returns unchanged coll.

Coerces a sequence of values `coll` from database types by calling a function
returned by invoking `io.randomseed.utils.db/out-coercer` multimethod on a qualified keyword
`table-column` (or a qualified keyword made out of `table` and `column`). If there
is no coercer attached for the keyword, tries with a keyword created using the
`column-kw` function (to use column alone). If there is no coercer, returns
unchanged `coll`.
sourceraw docstring

coerce-seq-out*clj

(coerce-seq-out* table-column coll)

Same as coerce-seq-out but table-column must be a lisp-cased keyword (already a result of colspec-kw or column-kw).

Same as `coerce-seq-out` but `table-column` must be a lisp-cased keyword (already a
result of `colspec-kw` or `column-kw`).
sourceraw docstring

data-source?clj

(data-source? v)

Returns true if v is an instance of javax.sql.DataSource.

Returns `true` if `v` is an instance of `javax.sql.DataSource`.
sourceraw docstring

defcoercionscljmacro

(defcoercions table & specs)

Defines input and output coercions for a database table table. The specs should be an argument list consisting of triples in a form of column-name, input-coercer, output-coercer.

For each definition 4 multimethod implementations will be emitted, identified by a keyword having a namespace the same as the given table, and a name the same as currently processed column name, both in 2 variants: one for snake, and one for lisp case. Two multimethod definitions will be created for io.randomseed.utils.db/in-coercer and two for io.randomseed.utils.db/out-coercer.

If the given coercer is a literal nil or false value, it will be marked as undefined using false value. It is advised to use that approach instead of assigning identity function to express that coercion is not needed since it can cause compile-time calculations to short-circuit instead of generating fallback code.

Example:

(defcoercions :users :some-identifier str keyword)

The above will expand the following code:

(defmethod io.randomseed.utils.db/in-coercer  :users/some-identifier [_] str)
(defmethod io.randomseed.utils.db/in-coercer  :users/some_identifier [_] str)
(defmethod io.randomseed.utils.db/out-coercer :users/some-identifier [_] keyword)
(defmethod io.randomseed.utils.db/out-coercer :users/some_identifier [_] keyword)

This will allow specialized database coercion functions to transformed values which are exchanged with a database.

Optionally coercions can be defined without a table name. In such case the table should be set to either nil, false or :io.randomseed.utils.db/any.

Defines input and output coercions for a database table `table`. The `specs` should
be an argument list consisting of triples in a form of `column-name`,
`input-coercer`, `output-coercer`.

For each definition 4 multimethod implementations will be emitted, identified by a
keyword having a namespace the same as the given table, and a name the same as
currently processed column name, both in 2 variants: one for snake, and one for
lisp case. Two multimethod definitions will be created for
`io.randomseed.utils.db/in-coercer` and two for `io.randomseed.utils.db/out-coercer`.

If the given coercer is a literal `nil` or `false` value, it will be marked as
undefined using `false` value. It is advised to use that approach instead of
assigning `identity` function to express that coercion is not needed since it can
cause compile-time calculations to short-circuit instead of generating fallback
code.

Example:

`(defcoercions :users :some-identifier str keyword)`

The above will expand the following code:

```
(defmethod io.randomseed.utils.db/in-coercer  :users/some-identifier [_] str)
(defmethod io.randomseed.utils.db/in-coercer  :users/some_identifier [_] str)
(defmethod io.randomseed.utils.db/out-coercer :users/some-identifier [_] keyword)
(defmethod io.randomseed.utils.db/out-coercer :users/some_identifier [_] keyword)
```

This will allow specialized database coercion functions to transformed values which
are exchanged with a database.

Optionally coercions can be defined without a table name. In such case the table
should be set to either `nil`, `false` or `:io.randomseed.utils.db/any`.
sourceraw docstring

execute!clj

(execute! connectable sql-params)
(execute! connectable sql-params opts)

Executes a SQL query via next.jdbc/execute! with coercing options (simple lisp-cased keys, map results). Returns a vector of result maps.

Executes a SQL query via `next.jdbc/execute!` with coercing options (simple
lisp-cased keys, map results). Returns a vector of result maps.
sourceraw docstring

execute-one!clj

(execute-one! connectable sql-params)
(execute-one! connectable sql-params opts)

Executes a SQL query via next.jdbc/execute-one! with coercing options (simple lisp-cased keys, map result). Returns nil when no row is found.

Executes a SQL query via `next.jdbc/execute-one!` with coercing options (simple
lisp-cased keys, map result). Returns `nil` when no row is found.
sourceraw docstring

for-insert-multi-orclj

(for-insert-multi-or table cols rows opts)

Given a table name, a vector of column names, and a vector of row values (each row is a vector of its values), return a vector of the full INSERT SQL string and its parameters. Applies any :table-fn / :column-fn supplied in the options. If :suffix is provided in opts, that string is appended to the INSERT IGNORE ... statement. The IGNORE part can be replaced by supplying :alt-clause option key.

Given a table name, a vector of column names, and a vector of row values
(each row is a vector of its values), return a vector of the full `INSERT` SQL
string and its parameters.  Applies any `:table-fn` / `:column-fn` supplied in the
options.  If `:suffix` is provided in `opts`, that string is appended to the
`INSERT IGNORE ...` statement. The `IGNORE` part can be replaced by
supplying :alt-clause option key.
sourceraw docstring

for-insert-orclj

(for-insert-or table key-map opts)

Given a table name and a hash map of column names and their values, return a vector of the full INSERT OR IGNORE SQL string and its parameters. Applies any :table-fn / :column-fn supplied in the options. If :suffix is provided in opts, that string is appended to the INSERT ... statement. If :alt-clause is provided in opts, it will replace the default IGNORE string.

Given a table name and a hash map of column names and their values,
return a vector of the full `INSERT OR IGNORE` SQL string and its parameters.
Applies any `:table-fn` / `:column-fn` supplied in the options.  If `:suffix` is
provided in `opts`, that string is appended to the `INSERT ...` statement. If
`:alt-clause` is provided in `opts`, it will replace the default IGNORE string.
sourceraw docstring

for-replaceclj

(for-replace table key-map opts)

Given a table name and a hash map of column names and their values, return a vector of the full REPLACE SQL string and its parameters. Applies any :table-fn / :column-fn supplied in the options. If :suffix is provided in opts, that string is appended to the INSERT ... statement.

Given a table name and a hash map of column names and their values,
return a vector of the full `REPLACE` SQL string and its parameters.
Applies any `:table-fn` / `:column-fn` supplied in the options.  If `:suffix` is
provided in `opts`, that string is appended to the `INSERT ...` statement.
sourceraw docstring

for-replace-multiclj

(for-replace-multi table cols rows opts)

Given a table name, a vector of column names, and a vector of row values (each row is a vector of its values), return a vector of the full REPLACE SQL string and its parameters. Applies any :table-fn / :column-fn supplied in the options. If :suffix is provided in opts, that string is appended to the REPLACE ... statement.

Given a table name, a vector of column names, and a vector of row values
(each row is a vector of its values), return a vector of the full `REPLACE` SQL
string and its parameters.  Applies any `:table-fn` / `:column-fn` supplied in the
options.  If `:suffix` is provided in `opts`, that string is appended to the
`REPLACE ...` statement.
sourceraw docstring

gen-builderclj

(gen-builder rs-builder)

Generates result set builder on a basis of the given builder rs-builder. Uses io.randomseed.utils.db/column-by-index-fn to coerce the results.

Generates result set builder on a basis of the given builder `rs-builder`. Uses
`io.randomseed.utils.db/column-by-index-fn` to coerce the results.
sourceraw docstring

gen-builder-delayedclj

(gen-builder-delayed rs-builder)

Generates result set builder on a basis of the given builder rs-builder. Uses io.randomseed.utils.db/delayed-column-by-index-fn to coerce the results.

Generates result set builder on a basis of the given builder `rs-builder`. Uses
`io.randomseed.utils.db/delayed-column-by-index-fn` to coerce the results.
sourceraw docstring

gen-qs-keywordclj

(gen-qs-keyword qs)
(gen-qs-keyword qs v)
(gen-qs-keyword t c v)

Generates unique but deterministic symbolic name for t (presumably table name), c (column name) and v (value, being an identifier). Returns a keyword named like DB__[t]_[c]_[v]_[nnnnnnn] where [t], [c] and [v] are string representations of the given argument values, and [nnnnnnn] is a numeric representation of combined hash of all values given as arguments.

Generates unique but deterministic symbolic name for `t` (presumably table name),
`c` (column name) and `v` (value, being an identifier). Returns a keyword named
like `DB__[t]_[c]_[v]_[nnnnnnn]` where `[t]`, `[c]` and `[v]` are string
representations of the given argument values, and `[nnnnnnn]` is a numeric
representation of combined hash of all values given as arguments.
sourceraw docstring

get-cachedclj

(get-cached cache db-getter db id)
(get-cached cache table db id)
(get-cached cache table db-getter db id)
(get-cached cache db-getter db id & more)
(get-cached cache table db id & more)
(get-cached cache table db-getter db id & more)

Returns a (possibly cached) sequence of maps requested using db-getter for the given IDs. A database connection and a table name can be passed to be used with the standard get-id getter function instead. When multiple IDs are given, calls get-cached-coll.

Returns a (possibly cached) sequence of maps requested using db-getter for the given
IDs. A database connection and a table name can be passed to be used with the
standard get-id getter function instead. When multiple IDs are given, calls
get-cached-coll.
sourceraw docstring

get-cached-collclj

(get-cached-coll cache db-getter db ids)
(get-cached-coll cache table db ids)
(get-cached-coll cache table db-getter db ids)

Returns a (possibly cached) sequence of maps requested using db-getter for the given IDs. When called with a table name it will be passed as a second argument to the given getter function. When no getter is given the standard one (get-ids) is used. Use make-getter-coll to create getter (with or without predefined table name).

Returns a (possibly cached) sequence of maps requested using db-getter for the given
IDs. When called with a table name it will be passed as a second argument to the
given getter function. When no getter is given the standard one (get-ids) is
used. Use make-getter-coll to create getter (with or without predefined table
name).
sourceraw docstring

get-cached-coll-propclj

(get-cached-coll-prop cache db-getter db property ids)
(get-cached-coll-prop cache table db property ids)
(get-cached-coll-prop cache table db-getter db property ids)

Uses get-cached-coll to retrieve a map with keys being IDs and values being requested properties. If there is no data for the given ID, corresponding entry is not added to the resulting map. If the property does not exist, nil is added.

Uses get-cached-coll to retrieve a map with keys being IDs and values being
requested properties. If there is no data for the given ID, corresponding entry is
not added to the resulting map. If the property does not exist, nil is added.
sourceraw docstring

get-cached-propclj

(get-cached-prop cache db-getter db property id)
(get-cached-prop cache table db property id)
(get-cached-prop cache table db-getter db property id)
(get-cached-prop cache db-getter db property id & more)
(get-cached-prop cache table db property id & more)
(get-cached-prop cache table db-getter db property id & more)

Same as get-cached but retrieves a single property from the result by using the get function. When multiple IDs are given it calls get-cached-coll-prop to handle it.

Same as get-cached but retrieves a single property from the result by using the get
function. When multiple IDs are given it calls get-cached-coll-prop to handle it.
sourceraw docstring

get-cached-prop-or-defaultclj

(get-cached-prop-or-default cache db-getter db property default id)
(get-cached-prop-or-default cache table db property default id)
(get-cached-prop-or-default cache table db-getter db property default id)
(get-cached-prop-or-default cache db-getter db property default id & more)
(get-cached-prop-or-default cache table db property default id & more)
(get-cached-prop-or-default cache table db-getter db property default id & more)

Same as get-cached-prop but when there is no entry for the given ID, it returns the given default value.

Same as get-cached-prop but when there is no entry for the given ID, it returns the
given default value.
sourceraw docstring

get-failed?clj

(get-failed? v)

Returns true if getting from a database failed in post-processing phase (e.g. de-serialization) and the data were broken.

Returns true if getting from a database failed in post-processing
phase (e.g. de-serialization) and the data were broken.
sourceraw docstring

get-idclj

(get-id db table id)
(get-id db table id & more)

Gets properties of the given ID from a database table. For multiple IDs, calls get-ids.

Gets properties of the given ID from a database table. For multiple IDs, calls
get-ids.
sourceraw docstring

get-idsclj

(get-ids db table ids)

Gets a map of ID-to-properties from a database for the given IDs and a table. Assumes each result will be related to a single, unique ID.

Gets a map of ID-to-properties from a database for the given IDs and a
table. Assumes each result will be related to a single, unique ID.
sourceraw docstring

get-in-coercerclj

(get-in-coercer table-column)
(get-in-coercer table column)

Tries to obtain a database coercion function by calling in-coercer multimethod for column and table specified with table and column, or by a single table-column. Transforms arguments to a lisp-cased keyword. If there is no coercer for table and column, tries to getting one using the column alone.

Returns coercer when it is found. Returns false when a coercer is found but explicitly set to undefined. Returns nil when there is no coercer.

Tries to obtain a database coercion function by calling `in-coercer` multimethod for
column and table specified with `table` and `column`, or by a single
`table-column`. Transforms arguments to a lisp-cased keyword. If there is no
coercer for table and column, tries to getting one using the column alone.

Returns coercer when it is found. Returns `false` when a coercer is found but
explicitly set to undefined. Returns `nil` when there is no coercer.
sourceraw docstring

get-in-coercer*clj

(get-in-coercer* table-column)

Same as get-in-coercer but trusts that table-column is a fully-qualified keyword (already a result of colspec-kw).

Same as `get-in-coercer` but trusts that `table-column` is a fully-qualified
keyword (already a result of `colspec-kw`).
sourceraw docstring

get-out-coercerclj

(get-out-coercer table-column)
(get-out-coercer table column)

Tries to obtain a database coercion function by calling out-coercer multimethod for column and table specified with table and column, or by a single table-column. Transforms arguments to a lisp-cased keyword. If there is no coercer for table and column, falls back to getting one using the column alone.

Returns coercer when it is found. Returns false when a coercer is found but explicitly set to undefined. Returns nil when there is no coercer.

Tries to obtain a database coercion function by calling `out-coercer` multimethod
for column and table specified with `table` and `column`, or by a single
`table-column`. Transforms arguments to a lisp-cased keyword. If there is no
coercer for table and column, falls back to getting one using the column alone.

Returns coercer when it is found. Returns `false` when a coercer is found but
explicitly set to undefined. Returns `nil` when there is no coercer.
sourceraw docstring

get-out-coercer*clj

(get-out-coercer* table-column)

Same as get-out-coercer but trusts that table-column is a lisp-cased keyword (already a result of colspec-kw).

Same as `get-out-coercer` but trusts that `table-column` is a lisp-cased
keyword (already a result of `colspec-kw`).
sourceraw docstring

id-from-dbclj

(id-from-db v)

Converts the given ID retrieved from a database to a value suitable to be used in Clojure programs. If v is a number or a keyword, it is returned as is. Otherwise it is converted to a keyword.

Converts the given ID retrieved from a database to a value suitable to be used in
Clojure programs. If `v` is a number or a keyword, it is returned as is. Otherwise
it is converted to a keyword.
sourceraw docstring

id-to-dbclj

(id-to-db v)

Converts the given ID to a value suitable to be stored in a database. If v is a number, it is passed as is. Otherwise it is converted to a string.

Converts the given ID to a value suitable to be stored in a database. If `v` is a
number, it is passed as is. Otherwise it is converted to a string.
sourceraw docstring

in-coercercljmultimethod

(in-coercer table-column v)
(in-coercer column v)

Returns a coercer suitable for transforming the given argument v to a database-suitable value, assuming table and column specified by the given qualified keyword table-column.

Returns a coercer suitable for transforming the given argument `v` to a
database-suitable value, assuming table and column specified by the given qualified
keyword `table-column`.
sourceraw docstring

insert-multi-or!clj

(insert-multi-or! connectable table cols rows)
(insert-multi-or! connectable table cols rows opts)

Syntactic sugar over execute! to make inserting columns/rows easier. Same as insert-or! but supports multiple rows to be inserted at once.

Syntactic sugar over `execute!` to make inserting columns/rows easier.
Same as insert-or! but supports multiple rows to be inserted at once.
sourceraw docstring

insert-or!clj

(insert-or! connectable table key-map)
(insert-or! connectable table key-map opts)

Syntactic sugar over execute-one! to make inserting hash maps easier. Given a connectable object, a table name, and a data hash map, inserts the data as a single row in the database and attempts to return a map of generated keys. By default it uses INSERT OR IGNORE but the IGNORE can be changed to anything by supplying :alt-clause option in opts map.

Syntactic sugar over `execute-one!` to make inserting hash maps easier.
Given a connectable object, a table name, and a data hash map, inserts the data as
a single row in the database and attempts to return a map of generated keys. By
default it uses `INSERT OR IGNORE` but the `IGNORE` can be changed to anything by
supplying :alt-clause option in opts map.
sourceraw docstring

insert-or-ignore!clj

(insert-or-ignore! connectable table key-map)
(insert-or-ignore! connectable table key-map opts)

Syntactic sugar over execute-one! to make inserting hash maps easier. Given a connectable object, a table name, and a data hash map, inserts the data as a single row in the database and attempts to return a map of generated keys.

Syntactic sugar over `execute-one!` to make inserting hash maps easier.
Given a connectable object, a table name, and a data hash map, inserts the data as
a single row in the database and attempts to return a map of generated keys.
sourceraw docstring

insert-or-ignore-multi!clj

(insert-or-ignore-multi! connectable table cols rows)
(insert-or-ignore-multi! connectable table cols rows opts)

Syntactic sugar over execute! to make inserting columns/rows easier. Same as insert-multi! but supports :alt-clause option key.

Syntactic sugar over `execute!` to make inserting columns/rows easier.
Same as insert-multi! but supports :alt-clause option key.
sourceraw docstring

insert-or-replace!clj

(insert-or-replace! connectable table key-map)
(insert-or-replace! connectable table key-map opts)

Syntactic sugar over execute-one! to make inserting hash maps easier. Given a connectable object, a table name, and a data hash map, inserts the data as a single row in the database and attempts to return a map of generated keys.

Syntactic sugar over `execute-one!` to make inserting hash maps easier.
Given a connectable object, a table name, and a data hash map, inserts the data as
a single row in the database and attempts to return a map of generated keys.
sourceraw docstring

insert-or-replace-multi!clj

(insert-or-replace-multi! connectable table cols rows)
(insert-or-replace-multi! connectable table cols rows opts)

Syntactic sugar over execute! to make inserting columns/rows easier. Same as insert-multi! but supports :alt-clause option key.

Syntactic sugar over `execute!` to make inserting columns/rows easier.
Same as insert-multi! but supports :alt-clause option key.
sourceraw docstring

invalidate!clj

(invalidate! f)
(invalidate! f key-params)

Invalidates cache associated with memoized function f. If key-params are given it should be a cache key sequence or other structure (usually function arguments). If only function is given, it clears the whole cache.

Invalidates cache associated with memoized function `f`. If `key-params` are given
it should be a cache key sequence or other structure (usually function
arguments). If only function is given, it clears the whole cache.
sourceraw docstring

invalidate+!clj

(invalidate+! f)
(invalidate+! f key-params)

Invalidates cache associated with memoized function f. If key-params are given it should be a cache key sequence or other structure (usually function arguments), internally transformed to vector. If only function is given, it clears the whole cache. Supports functions memoized with memoize+.

Invalidates cache associated with memoized function `f`. If `key-params` are given
it should be a cache key sequence or other structure (usually function arguments),
internally transformed to vector. If only function is given, it clears the whole
cache. Supports functions memoized with `memoize+`.
sourceraw docstring

invalidatorclj

(invalidator f)

Generates invalidation function for the given memoized function f. The invalidation function takes arguments in the same way as memoized function. If they match a value in the associated cache, the entry is evicted. Supports functions memoized with memoize and memoize+.

Generates invalidation function for the given memoized function `f`. The
invalidation function takes arguments in the same way as memoized function. If they
match a value in the associated cache, the entry is evicted. Supports functions
memoized with `memoize` and `memoize+`.
sourceraw docstring

lazy-docljmacro

(lazy-do & cmd)

Evaluates cmd and converts a non-nil result to a lazy map using map/to-lazy.

Evaluates `cmd` and converts a non-nil result to a lazy map using `map/to-lazy`.
sourceraw docstring

lazy-execute!clj

(lazy-execute! connectable sql-params)
(lazy-execute! connectable sql-params opts)

Executes a SQL query via next.jdbc/execute! with lazy coercing options. Each result map in the returned vector is converted to a lazy map. Returns nil when no rows are found.

Executes a SQL query via `next.jdbc/execute!` with lazy coercing options. Each
result map in the returned vector is converted to a lazy map. Returns `nil` when
no rows are found.
sourceraw docstring

lazy-execute-one!clj

(lazy-execute-one! connectable sql-params)
(lazy-execute-one! connectable sql-params opts)

Executes a SQL query via next.jdbc/execute-one! with lazy coercing options. The result map is converted to a lazy map. Returns nil when no row is found.

Executes a SQL query via `next.jdbc/execute-one!` with lazy coercing options. The
result map is converted to a lazy map. Returns `nil` when no row is found.
sourceraw docstring

lazy-get-by-idclj

(lazy-get-by-id connectable table pk)
(lazy-get-by-id connectable table pk opts)
(lazy-get-by-id connectable table pk pk-name opts)

Like next.jdbc/get-by-id but supports lazy maps.

Like `next.jdbc/get-by-id` but supports lazy maps.
sourceraw docstring

make-deleterclj

(make-deleter id-col)
(make-deleter table id-col)

Creates a database deleter function that removes a row identified by id-col. If table is given, the table name is baked into the query.

Creates a database deleter function that removes a row identified by `id-col`.
If `table` is given, the table name is baked into the query.
sourceraw docstring

make-getterclj

(make-getter f opts id-col cols)
(make-getter f opts table id-col cols)
(make-getter f opts table id-col cols getter-coll-fn)

Creates a coercion-aware database getter. Uses f (typically execute-one! or lazy-execute-one!) with the given opts to execute a SELECT query. When table is provided, it is baked into the query; otherwise it must be passed at call-time. When getter-coll-fn is provided, calls with extra IDs are delegated to it.

Creates a coercion-aware database getter. Uses `f` (typically `execute-one!` or
`lazy-execute-one!`) with the given `opts` to execute a SELECT query. When `table`
is provided, it is baked into the query; otherwise it must be passed at call-time.
When `getter-coll-fn` is provided, calls with extra IDs are delegated to it.
sourceraw docstring

make-getter-collclj

(make-getter-coll f opts id-col)
(make-getter-coll f opts id-col cols)
(make-getter-coll f opts table id-col cols)

Creates a database getter suitable for use with get-cached-coll- family of functions. The returned function should accept an argument containing multiple identifiers.

Creates a database getter suitable for use with `get-cached-coll-` family of
functions. The returned function should accept an argument containing multiple
identifiers.
sourceraw docstring

make-setterclj

(make-setter id-col)
(make-setter table id-col)

Creates a database setter function that updates a row identified by id-col. If table is given, the table name is baked into the function.

Creates a database setter function that updates a row identified by `id-col`.
If `table` is given, the table name is baked into the function.
sourceraw docstring

make-setting-deleterclj

(make-setting-deleter table entity-column)

Creates a setting deleter on a basis of the given table and entity column.

Creates a setting deleter on a basis of the given table and entity column.
sourceraw docstring

make-setting-getterclj

(make-setting-getter table entity-column)

Returns a function which gets a setting for the given entity and de-serializes it to a Clojure data structure. Table name and entity column name must be quoted if needed before passing to this function.

Returns a function which gets a setting for the given entity and de-serializes it to
a Clojure data structure. Table name and entity column name must be quoted if
needed before passing to this function.
sourceraw docstring

make-setting-setterclj

(make-setting-setter table entity-column)

Returns a function which stores one or more settings for a given entity in a database. Max. object size is 32 KB. Table name and entity column name must be quoted if needed before passing to this function.

Returns a function which stores one or more settings for a given entity in a
database. Max. object size is 32 KB. Table name and entity column name must be
quoted if needed before passing to this function.
sourceraw docstring

map->clj

(map-> m)
(map-> table m)

Coerces map values from database types using out-coercer. In the 1-arity form, each key is used as-is (must be qualified) to dispatch the coercer. In the 2-arity form, unqualified keys are qualified with table as the namespace.

Coerces map values from database types using `out-coercer`. In the 1-arity form,
each key is used as-is (must be qualified) to dispatch the coercer. In the 2-arity
form, unqualified keys are qualified with `table` as the namespace.
sourceraw docstring

memoizeclj

(memoize f)
(memoize f queue-size)
(memoize f queue-size ttl)

Creates memoized version of a database accessing or other function. With only 1 argument defaults to a FIFO cache with length of 256 and TTL cache with expiration of 150 seconds. When 2 arguments are given it only creates FIFO cache of the given length, without TTL. When queue-size is nil or <= 0, the FIFO cache will not be created. When ttl is nil or <= 0, the TTL cache will not be created.

Creates memoized version of a database accessing or other function. With only 1
argument defaults to a FIFO cache with length of 256 and TTL cache with expiration
of 150 seconds. When 2 arguments are given it only creates FIFO cache of the given
length, without TTL. When `queue-size` is `nil` or <= 0, the FIFO cache will not be
created. When `ttl` is `nil` or <= 0, the TTL cache will not be created.
sourceraw docstring

memoize+clj

(memoize+ f)
(memoize+ f size)
(memoize+ f level1-size level2-size)

Wrapper around clojure.core.memoize/fifo which uses fast, map-based memoization for cache size up to level1-size size, and then switches to slower memoization based on FIFO cache of level2-size size. The first level of cache is never purged automatically; once an element is there, it stays.

If only one size is given (size), the level-1 cache size will be set to 70% of it, and level-2 cache to 30% of it.

If no size is given, the level-1 cache will have a size of 89000 elements and level-2 cache will have a size of 39000 elements; both having a size of 128000 elements in total.

Be aware that caching key in level-1 cache is a vector of all arguments unless the argument count is greater than 8. In such case all extra arguments (expressed with native Clojure structure used for variadic function arguments) are grouped as 9th element of this vector.

To control caches associated with original function, use a metadata of the returned function object.

Wrapper around `clojure.core.memoize/fifo` which uses fast, map-based memoization
for cache size up to `level1-size` size, and then switches to slower memoization
based on FIFO cache of `level2-size` size. The first level of cache is never purged
automatically; once an element is there, it stays.

If only one size is given (`size`), the level-1 cache size will be set to 70% of
it, and level-2 cache to 30% of it.

If no size is given, the level-1 cache will have a size of 89000 elements and
level-2 cache will have a size of 39000 elements; both having a size of 128000
elements in total.

Be aware that caching key in level-1 cache is a vector of all arguments unless the
argument count is greater than 8. In such case all extra arguments (expressed with
native Clojure structure used for variadic function arguments) are grouped as 9th
element of this vector.

To control caches associated with original function, use a metadata of the returned
function object.
sourceraw docstring

memoizerclj

(memoizer config)
(memoizer f config)

Creates a memoized functions with predefined TTL and queue size taken from config. If the function is not given it will try to dereference symbol present in the config under the :memoizer key. Uses io.randomseed.utils.db/memoize to initialize caches.

Creates a memoized functions with predefined TTL and queue size taken from
config. If the function is not given it will try to dereference symbol present in
the config under the `:memoizer` key. Uses `io.randomseed.utils.db/memoize` to
initialize caches.
sourceraw docstring

not-found?clj

(not-found? e)

Returns true when the given value equals to :io.randomseed.utils.db/not-found.

Returns `true` when the given value equals to `:io.randomseed.utils.db/not-found`.
sourceraw docstring

opts-lazy-mapclj

next.jdbc options map: lisp-cased keys, map results, with delayed coercing builder.

next.jdbc options map: lisp-cased keys, map results, with delayed coercing builder.
sourceraw docstring

opts-lazy-simple-mapclj

next.jdbc options map: simple lisp-cased keys, map results, with delayed coercing builder.

next.jdbc options map: simple lisp-cased keys, map results, with delayed coercing builder.
sourceraw docstring

opts-lazy-simple-vecclj

next.jdbc options map: simple lisp-cased keys, vector results, with delayed coercing builder.

next.jdbc options map: simple lisp-cased keys, vector results, with delayed coercing builder.
sourceraw docstring

opts-lazy-slashed-mapclj

next.jdbc options map: lisp-cased slashed keys, map results, with delayed coercing builder.

next.jdbc options map: lisp-cased slashed keys, map results, with delayed coercing builder.
sourceraw docstring

opts-lazy-slashed-vecclj

next.jdbc options map: lisp-cased slashed keys, vector results, with delayed coercing builder.

next.jdbc options map: lisp-cased slashed keys, vector results, with delayed coercing builder.
sourceraw docstring

opts-lazy-vecclj

next.jdbc options map: lisp-cased keys, vector results, with delayed coercing builder.

next.jdbc options map: lisp-cased keys, vector results, with delayed coercing builder.
sourceraw docstring

opts-mapclj

next.jdbc options map: lisp-cased keys, map results, with coercing builder.

next.jdbc options map: lisp-cased keys, map results, with coercing builder.
sourceraw docstring

opts-simple-mapclj

next.jdbc options map: simple lisp-cased keys (no table prefix), map results, with coercing builder.

next.jdbc options map: simple lisp-cased keys (no table prefix), map results, with coercing builder.
sourceraw docstring

opts-simple-vecclj

next.jdbc options map: simple lisp-cased keys, vector results, with coercing builder.

next.jdbc options map: simple lisp-cased keys, vector results, with coercing builder.
sourceraw docstring

opts-slashed-mapclj

next.jdbc options map: lisp-cased slashed keys, map results, with coercing builder.

next.jdbc options map: lisp-cased slashed keys, map results, with coercing builder.
sourceraw docstring

opts-slashed-vecclj

next.jdbc options map: lisp-cased slashed keys, vector results, with coercing builder.

next.jdbc options map: lisp-cased slashed keys, vector results, with coercing builder.
sourceraw docstring

opts-vecclj

next.jdbc options map: lisp-cased keys, vector results, with coercing builder.

next.jdbc options map: lisp-cased keys, vector results, with coercing builder.
sourceraw docstring

out-coercercljmultimethod

(out-coercer table-column v)
(out-coercer column v)

Returns a coercer suitable for transforming the given argument v read from a database, assuming table and column specified by the given qualified keyword table-column.

Returns a coercer suitable for transforming the given argument `v` read from a
database, assuming table and column specified by the given qualified keyword
`table-column`.
sourceraw docstring

replace!clj

(replace! connectable table key-map)
(replace! connectable table key-map opts)

Syntactic sugar over execute-one! to make inserting hash maps easier. Given a connectable object, a table name, and a data hash map, inserts the data as a single row in the database and attempts to return a map of generated keys. By default it uses REPLACE.

Syntactic sugar over `execute-one!` to make inserting hash maps easier.
Given a connectable object, a table name, and a data hash map, inserts the data as
a single row in the database and attempts to return a map of generated keys. By
default it uses `REPLACE`.
sourceraw docstring

replace-multi!clj

(replace-multi! connectable table cols rows)
(replace-multi! connectable table cols rows opts)

Syntactic sugar over execute! to make inserting columns/rows easier. Same as replace! but supports multiple rows to be inserted at once.

Syntactic sugar over `execute!` to make inserting columns/rows easier.
Same as replace! but supports multiple rows to be inserted at once.
sourceraw docstring

seq->cljmacro

(seq-> table-column coll)
(seq-> table column coll)

Coerces a sequence of values coll from database types by calling a function returned by invoking io.randomseed.utils.db/out-coercer multimethod on a qualified keyword table-column (or a qualified keyword made out of table and column). If there is no coercer attached for the keyword, returns unchanged coll.

If both, a table and a column can be used to establish coercion function at compile-time, a mapping form will be generated which uses that function.

Coerces a sequence of values `coll` from database types by calling a function
returned by invoking `io.randomseed.utils.db/out-coercer` multimethod on a qualified keyword
`table-column` (or a qualified keyword made out of `table` and `column`). If there
is no coercer attached for the keyword, returns unchanged `coll`.

If both, a table and a column can be used to establish coercion function at
compile-time, a mapping form will be generated which uses that function.
sourceraw docstring

simple->clj

(simple-> table m)

Coerces map values from database types using out-coercer, qualifying each key with table as the namespace. Returns a new map with coerced values.

Coerces map values from database types using `out-coercer`, qualifying each key
with `table` as the namespace. Returns a new map with coerced values.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close