Common API to communicate with PostgreSQL server.
Common API to communicate with PostgreSQL server.
(->conn-config params)
Turn a Clojure map into an instance of ConnConfig.Builder.
Turn a Clojure map into an instance of ConnConfig.Builder.
(->enum x)
Wrap a value with a PGEnum class for proper enum encoding
Wrap a value with a PGEnum class for proper enum encoding
(->execute-params opt)
Make an instance of ExecuteParams from a Clojure map.
Make an instance of ExecuteParams from a Clojure map.
(->kebab column)
Turn a string column name into into a kebab-case formatted keyword.
Turn a string column name into into a kebab-case formatted keyword.
(->LogLevel log-level)
Turn a keyword into an instance of System.Logger.Level enum.
Turn a keyword into an instance of System.Logger.Level enum.
(->tx-level level)
Turn a keyword or a string into on instance of TxLevel.
Turn a keyword or a string into on instance of TxLevel.
(cancel-request conn)
Send a cancellation request to the server. MUST be called in another thread! The cancellation is meant to interrupt a query that has frozen the server. There is no 100% guarantee it will work.
Not recommended to use directly. See the with-timeout
macro.
Send a cancellation request to the server. MUST be called in another thread! The cancellation is meant to interrupt a query that has frozen the server. There is no 100% guarantee it will work. Not recommended to use directly. See the `with-timeout` macro.
(clone conn)
Create a new Connection from a configuration of the given connection.
Create a new Connection from a configuration of the given connection.
(close conn)
Close the connection to the database.
Close the connection to the database.
(close-statement conn stmt)
Close the prepared statement.
Close the prepared statement.
(closed? conn)
True if the connection has been closed.
True if the connection has been closed.
(commit conn)
Commit the current transaction.
Commit the current transaction.
(connect config)
(connect host port user password database)
Connect to the database. Given a Clojure config map, establish a TCP connection with the server and run the authentication pipeline. Returns an instance of the Connection class.
Connect to the database. Given a Clojure config map, establish a TCP connection with the server and run the authentication pipeline. Returns an instance of the Connection class.
(connection? x)
True of the passed option is a Connection instance.
True of the passed option is a Connection instance.
(copy-in conn sql in)
(copy-in conn sql in opt)
Transfer the data from the client to the server using COPY protocol. The SQL expression must be something liek this:
COPY ... FROM STDIN ...
The in
parameter is an instance of InputStream
. The function
doesn't close the stream assuming you can reuse it.
The opt
map is used to specify format, CSV delimiters, type hints
and other options (see README).
Return the number of rows processed by the server.
Transfer the data from the client to the server using COPY protocol. The SQL expression must be something liek this: `COPY ... FROM STDIN ...` The `in` parameter is an instance of `InputStream`. The function doesn't close the stream assuming you can reuse it. The `opt` map is used to specify format, CSV delimiters, type hints and other options (see README). Return the number of rows processed by the server.
(copy-in-maps conn sql maps keys)
(copy-in-maps conn sql maps keys opt)
Like copy-in
but accepts a list of Clojure maps.
The keys
argument is list of keys which is used to convert
each map into a tuple.
The opt
argument is a map of options (COPY format, delimiters, etc).
Return the number of rows processed by the server.
Like `copy-in` but accepts a list of Clojure maps. The `keys` argument is list of keys which is used to convert each map into a tuple. The `opt` argument is a map of options (COPY format, delimiters, etc). Return the number of rows processed by the server.
(copy-in-rows conn sql rows)
(copy-in-rows conn sql rows opt)
Like copy-in
but accepts not an input stream but a list
of rows. Each row must be a list of values. The list might be
lazy. Return a number of rows processed.
Like `copy-in` but accepts not an input stream but a list of rows. Each row must be a list of values. The list might be lazy. Return a number of rows processed.
(copy-out conn sql out)
(copy-out conn sql out opt)
Transfer the data from the server to the client using COPY protocol. The SQL expression must be something like this:
COPY ... TO STDOUT ...
The out
parameter must be an instance of OutputStream.
The function doesn't close the stream assuming you can reuse it for multiple COPY OUT sessions.
The opt
map allows to specify the data format, CSV delimiters
other options (see the docs in README).
Return the number of rows read from the server.
Transfer the data from the server to the client using COPY protocol. The SQL expression must be something like this: `COPY ... TO STDOUT ...` The `out` parameter must be an instance of OutputStream. The function doesn't close the stream assuming you can reuse it for multiple COPY OUT sessions. The `opt` map allows to specify the data format, CSV delimiters other options (see the docs in README). Return the number of rows read from the server.
(created-at conn)
Get the creation time as Unix timestamp (ms).
Get the creation time as Unix timestamp (ms).
(decode-bin buf oid)
Decode a binary-encoded value from a ByteBuffer.
Decode a binary-encoded value from a ByteBuffer.
(decode-txt obj oid)
Decode a text-encoded value from a ByteBuffer.
Decode a text-encoded value from a ByteBuffer.
(encode-bin obj)
(encode-bin obj oid)
Binary-encode a value into a ByteBuffer.
Binary-encode a value into a ByteBuffer.
(encode-txt obj)
(encode-txt obj oid)
Text-encode a value into a ByteBuffer.
Text-encode a value into a ByteBuffer.
(execute conn sql)
(execute conn sql opt)
Execute a SQL expression and return the result.
This function is a series of steps:
Execute a SQL expression and return the result. This function is a series of steps: - prepare a statement; - bind parameters and obtain a portal; - describe the portal; - get the data from the portal; - close the portal; - close the statement; - process the result of the fly.
(execute-statement conn stmt)
(execute-statement conn stmt opt)
Execute the given prepared statement and get the result. The way the result is processed heavily depends on the options.
Execute the given prepared statement and get the result. The way the result is processed heavily depends on the options.
(get-parameter conn param)
Return a certain connection parameter by its name, e.g. 'server_encoding', 'application_name', etc.
Return a certain connection parameter by its name, e.g. 'server_encoding', 'application_name', etc.
(get-parameters conn)
Return a {String->String} map of all the connection parameters.
Return a {String->String} map of all the connection parameters.
(id conn)
Get a unique ID of the connection.
Get a unique ID of the connection.
(idle? conn)
True if the connection is in the idle state.
True if the connection is in the idle state.
(in-transaction? conn)
True if the connection is in transaction at the moment.
True if the connection is in transaction at the moment.
(is-ssl? conn)
True if the Connection is SSL-encrypted.
True if the Connection is SSL-encrypted.
(json-wrap x)
Wrap a value into a JSON.Wrapper class to force JSON encoding.
Wrap a value into a JSON.Wrapper class to force JSON encoding.
(listen conn channel)
Subscribe the connection to a given channel.
Subscribe the connection to a given channel.
(notify conn channel message)
Send a text message to the given channel.
Send a text message to the given channel.
(pid conn)
Get PID of the connection on the server.
Get PID of the connection on the server.
(prepare conn sql)
(prepare conn sql oids)
Get a new prepared statement from a raw SQL string.
The SQL might have parameters. There is an third
optional parameter oids
to specify the non-default types
of the parameters. Must be a List of OID enum.
The function returns an instance of the PreparedStatement
class bound to the current connection.
Get a new prepared statement from a raw SQL string. The SQL might have parameters. There is an third optional parameter `oids` to specify the non-default types of the parameters. Must be a List of OID enum. The function returns an instance of the `PreparedStatement` class bound to the current connection.
(prepared-statement? x)
True if it's an instance of the PreparedStatement class.
True if it's an instance of the PreparedStatement class.
(query conn sql)
(query conn sql opt)
Run a SQL expression WITH NO parameters. The result gets sent back in text mode always by the server.
Run a SQL expression WITH NO parameters. The result gets sent back in text mode always by the server.
(rollback conn)
Rollback the current transaction.
Rollback the current transaction.
(set-read-only conn)
Set the current transaction read-only.
Set the current transaction read-only.
(set-tx-level conn level)
Set transaction isolation level for the current transaction.
Set transaction isolation level for the current transaction.
(ssl-context {:keys [key-file cert-file ca-cert-file]})
Build a SSLContext instance from a Clojure map. All the keys point to local files.
Build a SSLContext instance from a Clojure map. All the keys point to local files.
(ssl? conn)
True if the connection is encrypted with SSL.
True if the connection is encrypted with SSL.
(status conn)
Return the current transaction status, one of :I, :T, or :E.
Return the current transaction status, one of :I, :T, or :E.
(tx-error? conn)
True if the transaction has failed but hasn't been rolled back yet.
True if the transaction has failed but hasn't been rolled back yet.
(unlisten conn channel)
Unsubscribe the connection from a given channel.
Unsubscribe the connection from a given channel.
(with-connection [bind config] & body)
Execute the body while the bind
symbol is bound to the
new Connection instance. The connection gets closed when
exiting the macro.
Execute the body while the `bind` symbol is bound to the new Connection instance. The connection gets closed when exiting the macro.
(with-statement [bind conn sql oids] & body)
Execute the body while the bind
symbol is bound to the
new PreparedStatement instance. The statement gets created
from the SQL expression and optional list of OIDs. It gets
closed when exiting the macro.
Execute the body while the `bind` symbol is bound to the new PreparedStatement instance. The statement gets created from the SQL expression and optional list of OIDs. It gets closed when exiting the macro.
(with-timeout [conn ms-timeout] & body)
Set a timeout in which, if a query has not been executed in time,
a cancellation request is sent to the server. Wrap a query with
that macro when there is a chance for a server to freeze completely
due to a non-optimized SQL. The ms-timeout
is amount of milliseconds
in which the cancel request will be sent.
Set a timeout in which, if a query has not been executed in time, a cancellation request is sent to the server. Wrap a query with that macro when there is a chance for a server to freeze completely due to a non-optimized SQL. The `ms-timeout` is amount of milliseconds in which the cancel request will be sent.
(with-tx [conn {:as opt :keys [isolation-level read-only? rollback?]}] & body)
Wrap a block of code into a transaction, namely:
Accepts a map of the following options:
Wrap a block of code into a transaction, namely: - run BEGIN before executing the code; - capture all possible exceptions; - should an exception was caught, ROLLBACK... - and re-throw it; - if no exception was caught, COMMIT. Accepts a map of the following options: - isolation-level: a keyword/string to set the isolation level; - read-only?: to set the transaction read only; - rollback?: to ROLLBACK a transaction even if it was successful.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close