(aggregate-column column under results)
Given a sequence of rows as maps, aggregate the values of column
into a sequence under under
, combining rows that are equal except
for the value of column
. Useful for consolidating the results of an
outer join.
Given a sequence of rows as maps, aggregate the values of `column` into a sequence under `under`, combining rows that are equal except for the value of `column`. Useful for consolidating the results of an outer join.
(aggregate-submap-by agg-key agg-val under-key results)
Given a sequence of maps in results where each map contains agg-key and agg-val as keys, groups the maps that are identical except for the values in agg-key or agg-val. The values of agg-key and agg-val are turned into a map and stored in the resulting map under under-key.
Given a sequence of maps in results where each map contains agg-key and agg-val as keys, groups the maps that are identical except for the values in agg-key or agg-val. The values of agg-key and agg-val are turned into a map and stored in the resulting map under under-key.
(connection-pool db-spec)
Given a DB spec map containing :subprotocol, :subname, :user, and :password keys, return a pooled DB spec map (one containing just the :datasource key with a pooled DataSource object as the value). The returned pooled DB spec can be passed directly as the first argument to clojure.java.jdbc's functions.
Times out after 30 seconds and throws org.postgresql.util.PSQLException
Given a DB spec map containing :subprotocol, :subname, :user, and :password keys, return a pooled DB spec map (one containing just the :datasource key with a pooled DataSource object as the value). The returned pooled DB spec can be passed directly as the first argument to clojure.java.jdbc's functions. Times out after 30 seconds and throws org.postgresql.util.PSQLException
(convert-result-arrays result-set)
(convert-result-arrays f result-set)
Converts Java and JDBC arrays in a result set using the provided function (eg. vec, set). Values which aren't arrays are unchanged.
Converts Java and JDBC arrays in a result set using the provided function (eg. vec, set). Values which aren't arrays are unchanged.
(convert-result-pgobjects result-set)
Converts PGObjects in a result set to be the value that they contain. Values which aren't arrays are unchanged.
Converts PGObjects in a result set to be the value that they contain. Values which aren't arrays are unchanged.
(create-db! admin-db-spec db-name db-owner)
Given a DB spec, the database's name, and the name of the user that will own
the database, creates the database db-name
owned by db-owner
, with the
DB's encoding set to UTF-8. The DB spec should connect to a different database
than the one being created, and the user in the DB spec must have the CREATEDB
permission. If the db-owner
differs from the user in the DB spec, then the
user in the DB spec must either be a member of the db-owner
role, or have
the CREATEROLE permission, or be a superuser.
NB: this function is not thread-safe when multiple threads create databases
with the same db-owner
, unless the :user specified in admin-db-spec
is
db-owner
, is otherwise a member of the db-owner
role, or is a superuser.
Given a DB spec, the database's name, and the name of the user that will own the database, creates the database `db-name` owned by `db-owner`, with the DB's encoding set to UTF-8. The DB spec should connect to a different database than the one being created, and the user in the DB spec must have the CREATEDB permission. If the `db-owner` differs from the user in the DB spec, then the user in the DB spec must either be a member of the `db-owner` role, or have the CREATEROLE permission, or be a superuser. NB: this function is not thread-safe when multiple threads create databases with the same `db-owner`, unless the :user specified in `admin-db-spec` is `db-owner`, is otherwise a member of the `db-owner` role, or is a superuser.
(create-user! admin-db-spec username password)
(create-user! admin-db-spec username password options)
Given a DB spec that has a user with permission to create roles and isn't
username
, create the user username
with the given password
. Accepts an
optional options map where the :superuser? option will make the created user
a superuser if the value is exactly true
(not just truthy); note that only
superusers can create more superusers.
Given a DB spec that has a user with permission to create roles and isn't `username`, create the user `username` with the given `password`. Accepts an optional options map where the :superuser? option will make the created user a superuser if the value is exactly `true` (not just truthy); note that only superusers can create more superusers.
(db-exists? admin-db-spec db-name)
Given a DB spec that connects to a database besides db-name
, return
a boolean indicating whether db-name
exists.
Given a DB spec that connects to a database besides `db-name`, return a boolean indicating whether `db-name` exists.
(drop-db! admin-db-spec db-name)
Given a DB spec that has a user with permission to drop the database
db-name
and that connects to a database that isn't db-name
, and the
database's name db-name
, drop that database named by db-name
.
Given a DB spec that has a user with permission to drop the database `db-name` and that connects to a database that isn't `db-name`, and the database's name `db-name`, drop that database named by `db-name`.
(drop-public-functions! db-spec)
Drops all public functions in a database. Super dangerous.
Drops all public functions in a database. Super dangerous.
(drop-public-tables! db-spec)
Drops all public tables in a database. Super dangerous.
Drops all public tables in a database. Super dangerous.
(drop-user! admin-db-spec username)
Given a DB spec that connects with a user besides username
and has
permisson to drop that user, remove the named user. Note that only superusers
can remove other superusers; other users can be removed by anyone with the
CREATEROLE permission.
Given a DB spec that connects with a user besides `username` and has permisson to drop that user, remove the named user. Note that only superusers can remove other superusers; other users can be removed by anyone with the CREATEROLE permission.
(expand-seq-params [sql & parameters])
A helper for prepared SQL statements with sequential parameters.
Returns a new prepared statement with every ?
that corresponded to a
sequential parameter expanded to a tuple literal of the appropriate
length and flattened parameters.
A helper for prepared SQL statements with sequential parameters. Returns a new prepared statement with every `?` that corresponded to a sequential parameter expanded to a tuple literal of the appropriate length and flattened parameters.
(get-sequence-name-for-column db table column)
Returns the name of the sequence associated with a column, or nil if there is no sequence.
Returns the name of the sequence associated with a column, or nil if there is no sequence.
(has-role? db-spec user role)
Returns true if the user has permission to act as the member of the role, and false if not.
Returns true if the user has permission to act as the member of the role, and false if not.
(pg-escape-identifier s)
Escape an arbitrary string to make it safe to naively interpolate into an SQL string as an identifier. Use of this function is discouraged.
Escape an arbitrary string to make it safe to naively interpolate into an SQL string as an identifier. Use of this function is discouraged.
(pg-escape-string s)
Takes an arbitrary string, escapes any SQL quoting meta-characters, and returns it in SQL string literal format to be naively interpolated into an SQL string. Only for use with unplanned statements (those besides SELECT, INSERT, UPDATE, and DELETE), which do not accept query parameters.
Takes an arbitrary string, escapes any SQL quoting meta-characters, and returns it in SQL string literal format to be naively interpolated into an SQL string. Only for use with unplanned statements (those besides SELECT, INSERT, UPDATE, and DELETE), which do not accept query parameters.
(public-functions db-spec)
Get the names of all public functions in a database
Get the names of all public functions in a database
(public-tables db-spec)
Get the names of all public tables in a database
Get the names of all public tables in a database
(query db sql-and-params)
An implementation of query that returns a fully evaluated result (no lazy sequences, JDBCArray objects, or PGObjects).
An implementation of query that returns a fully evaluated result (no lazy sequences, JDBCArray objects, or PGObjects).
(quoted id)
Given a psql identifier like public.table-name or column-name, quotes it so that it is suitable to use in jdbc queries. E.g., public.table-name -> "public"."table-name" column-name -> "column-name"
Given a psql identifier like public.table-name or column-name, quotes it so that it is suitable to use in jdbc queries. E.g., public.table-name -> "public"."table-name" column-name -> "column-name"
(reconcile-sequence-for-column! db table column)
Finds the sequence associated with the given column and compares it to the max value in the column. If the sequence is lower, sets it equal to the max value. If the column has no associated sequence, throws an Exception.
Finds the sequence associated with the given column and compares it to the max value in the column. If the sequence is lower, sets it equal to the max value. If the column has no associated sequence, throws an Exception.
(user-exists? admin-db-spec username)
Given a DB spec that connects with a user besides username
, return
a boolean indicating whether username
exists.
Given a DB spec that connects with a user besides `username`, return a boolean indicating whether `username` exists.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close