Liking cljdoc? Tell your friends :D

io.randomseed.utils.db

Random utils, database helper functions.

Random utils, database helper functions.
raw docstring

braced-?clj

(braced-? coll)
source

braced-join-?clj

(braced-join-? ids)
source

braced-join-col-namesclj

(braced-join-col-names cols)
source

braced-join-col-names-no-convclj

(braced-join-col-names-no-conv cols)
source

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-id+clj

(cache-id+ f)

Returns metadata value associated with :io.randomseed.utils.db/cache key for the function f.

Returns metadata value associated with `:io.randomseed.utils.db/cache` key for the
function `f`.
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 get an initial map of entries. Returns a cache object.

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

cached-setting-delclj

(cached-setting-del cache deleter db entity-id)
(cached-setting-del cache deleter db entity-id setting-id)
(cached-setting-del cache deleter db entity-id setting-id & pairs)

Deletes the cached result of calling the given setting deleter. Purges cache entry after operation succeeded.

Deletes the cached result of calling the given setting deleter. Purges cache entry
after operation succeeded.
sourceraw docstring

cached-setting-getclj

(cached-setting-get cache getter db entity-id setting-id)
(cached-setting-get cache getter db entity-id setting-id & setting-ids)

Gets the cached result of calling the given setting getter. Updates cache when necessary.

Gets the cached result of calling the given setting getter. Updates cache when
necessary.
sourceraw docstring

cached-setting-setclj

(cached-setting-set cache setter db entity-id setting-id value)
(cached-setting-set cache setter db entity-id setting-id value & pairs)

Sets the cached result of calling the given setting setter. Purges cache entry after operation succeeded.

Sets the cached result of calling the given setting setter. Purges cache entry after
operation succeeded.
sourceraw docstring

cwr-lookupclj

(cwr-lookup cache id)

Performs a cache lookup of id on cache and returns the hit. If there is no element found, returns the keyword :io.randomseed.utils.db/not-found.

Performs a cache lookup of `id` on `cache` and returns the hit. If there is no
element found, returns the keyword `:io.randomseed.utils.db/not-found`.
sourceraw docstring

dashclj

source

data-source?clj

(data-source? v)
source

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

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

id-as-strclj

(id-as-str v)

Tries to convert the given argument to a string identifier.

Tries to convert the given argument to a string identifier.
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

init-cacheclj

(init-cache {:keys [size ttl seed]})

Initializes single cache by parsing TTL and queue size.

Initializes single cache by parsing TTL and queue size.
sourceraw docstring

init-cachesclj

(init-caches config)

Initializes in-memory caches by resetting atoms associated with cache parameters.

Initializes in-memory caches by resetting atoms associated with cache parameters.
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

join-?clj

(join-? ids)
source

join-col-namesclj

(join-col-names cols)
source

join-v=?clj

(join-v=? ids)
source

listed-nilclj

source

make-deleterclj

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

make-getterclj

(make-getter id-col cols)
(make-getter table id-col cols)
(make-getter table id-col cols getter-coll-fn)
source

make-getter-collclj

(make-getter-coll id-col)
(make-getter-coll id-col cols)
(make-getter-coll 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)
source

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

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

memoized+?clj

(memoized+? f)

Returns true if the given function f is memoized using memoize+. If not, returns false.

Returns `true` if the given function `f` is memoized using `memoize+`. If not,
returns `false`.
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-foundclj

source

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-mapclj

source

opts-simple-mapclj

source

opts-simple-vecclj

source

opts-slashed-mapclj

source

opts-slashed-vecclj

source

opts-vecclj

source

(print-caches caches)
source

remove-cachesclj

(remove-caches config)

Removes cache structures.

Removes cache structures.
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

to-lispclj

source

to-lisp-simpleclj

source

to-lisp-slashedclj

source

to-snakeclj

source

to-snake-simpleclj

source

to-snake-slashedclj

source

underscoreclj

source

values-?clj

(values-? coll)
source

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

× close