gungnir.database

*datasource*

dynamic

The global Gungnir datasource. This var is set using either using the gungnir.database/set-datasource! or gungnir.database/make-datasource! function.

*tx-datasource*

dynamic

This variable is only set during transactions. It allows the Gungnir internals to know that a transaction is taking place.

build-datasource!

(build-datasource! ?options)(build-datasource! url options)

The following options are supported for ?options * DATABASE_URL - The universal database url used by services such as Heroku / Render * JDBC_DATABASE_URL - The standard Java Database Connectivity URL * HikariCP configuration map - https://github.com/tomekw/hikari-cp#configuration-options When both url and options are supplied: url - DATABSE_URL or JDBC_DATABASE_URL options - HikariCP options

close!

(close!)(close! datasource)

Close the Hikari datasource. If no datasource is supplied it defaults to gungnir.database/*datasource*.

delete!

(delete! record)(delete! record datasource)

Delete a row from the database based on record which can either be a namespaced map or relational atom. The row will be deleted based on it’s primary-key. Return true on deletion. If no match is found return false.

exception->map

multimethod

format-error

(format-error column-k error-type)(format-error changeset column-k error-type)

insert!

(insert! changeset)(insert! {:changeset/keys [model errors result], :as changeset} datasource)

Insert a row based on the changeset provided. This function assumes that the :changeset/result key does not have a primary-key with a values. Returns the inserted row on succes. On failure return the changeset with an updated :changeset/errors key.

make-datasource!

(make-datasource! ?options)(make-datasource! url options)

Same as build-datasource! but also sets the created datasource globally.

query!

(query! form)(query! form datasource)

Execute a query based on the HoneySQL form and return a collection of maps. If no result is found return an empty vector.

query-1!

(query-1! form)(query-1! form datasource)

Execute a query based on the HoneySQL form and return a map. If no result is found return nil.

set-datasource!

(set-datasource! datasource)

Set the datasource to be used by Gungnir.

sql-key-from-quotes

(sql-key-from-quotes e)

try-uuid

(try-uuid ?uuid)

Try to convert ?uuid to a java.util.UUID if it is a string. Otherwise return ?uuid as supplied.

update!

(update! changeset)(update! {:changeset/keys [model errors diff origin transformed-origin], :as changeset} datasource)

Update a row based on the changeset provided. This function assumes that the :changeset/result key has a primary-key with a values. Returns the updated row on succes. On failure return the changeset with an updated :changeset/errors key.