Liking cljdoc? Tell your friends :D

pg.core

Common API to communicate with PostgreSQL server.

Common API to communicate with PostgreSQL server.
raw docstring

->codec-paramsclj

(->codec-params opt)
source

->tx-levelclj

(->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.
sourceraw docstring

beginclj

(begin conn)
(begin conn tx-level)
(begin conn tx-level read-only?)

Open a new transaction. Possible arguments:

  • tx-level: the custom isolation level, either a :kebab-case keyword, or a CAPS STRING, for example :read-committed or 'READ COMMITTED';
  • read-only?: whether to run the transaction in read-only mode (default is false).
Open a new transaction. Possible arguments:

- `tx-level`: the custom isolation level, either a `:kebab-case`
   keyword, or a CAPS STRING, for example `:read-committed`
   or `'READ COMMITTED'`;
- `read-only?`: whether to run the transaction in read-only mode
  (default is false).
sourceraw docstring

cancel-requestclj

(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.
sourceraw docstring

cloneclj

(clone src)

Produce another instance of a source with the same configuration.

Produce another instance of a source with the same
configuration.
sourceraw docstring

closeclj

(close src)

Close a data source. Closing a Connection terminates a session on the server side. Closing a Pool object terminates all open connections.

Close a data source. Closing a Connection terminates
a session on the server side. Closing a Pool object
terminates all open connections.
sourceraw docstring

close-cached-statementsclj

(close-cached-statements conn)

Close all the cached prepared statements and clean up the cache.

Close all the cached prepared statements
and clean up the cache.
sourceraw docstring

close-statementclj

(close-statement conn statement)

Close a prepared statement.

Close a prepared statement.
sourceraw docstring

closed?clj

(closed? src)

Whether the data source was closed. A closed source cannot be reused again.

Whether the data source was closed. A closed source
cannot be reused again.
sourceraw docstring

commitclj

(commit conn)

Commit the current transaction.

Commit the current transaction.
sourceraw docstring

connectclj

(connect src)
(connect host port user password database)

Connect to the database. Given a Clojure config map or a URI string, 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
or a URI string, establish a TCP connection with the
server and run the authentication pipeline. Returns
an instance of the Connection class.
sourceraw docstring

connection?clj

(connection? x)

True of the passed option is a Connection instance.

True of the passed option is a Connection instance.
sourceraw docstring

copy-inclj

(copy-in src sql in)
(copy-in src 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.
sourceraw docstring

copy-in-mapsclj

(copy-in-maps src sql maps keys)
(copy-in-maps src 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.
sourceraw docstring

copy-in-rowsclj

(copy-in-rows src sql rows)
(copy-in-rows src 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.
sourceraw docstring

copy-outclj

(copy-out src sql out)
(copy-out src 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.
sourceraw docstring

COPY_FORMAT_BINclj

source

COPY_FORMAT_CSVclj

source

COPY_FORMAT_TABclj

source

created-atclj

(created-at conn)

Get the connection creation time as a Unix timestamp (ms).

Get the connection creation time as a Unix timestamp (ms).
sourceraw docstring

decode-binclj

(decode-bin buf oid)
(decode-bin buf oid opt)

Decode a binary-encoded value from a ByteBuffer.

Decode a binary-encoded value from a ByteBuffer.
sourceraw docstring

decode-txtclj

(decode-txt obj oid)
(decode-txt obj oid opt)

Decode a text-encoded value from a ByteBuffer.

Decode a text-encoded value from a ByteBuffer.
sourceraw docstring

encode-binclj

(encode-bin obj)
(encode-bin obj oid)
(encode-bin obj oid opt)

Binary-encode a value into a ByteBuffer.

Binary-encode a value into a ByteBuffer.
sourceraw docstring

encode-txtclj

(encode-txt obj)
(encode-txt obj oid)
(encode-txt obj oid opt)

Text-encode a value into a string.

Text-encode a value into a string.
sourceraw docstring

executeclj

(execute src sql)
(execute src sql opt)

Execute a SQL expression and return a result. Arguments:

  • src is a data source (a Connection, a Pool, a map, a URI string);
  • sql is a SQL string expression;
  • opt is a map of options.

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 a SQL expression and return a result. Arguments:
- `src` is a data source (a Connection, a Pool, a map, a URI string);
- `sql` is a SQL string expression;
- `opt` is a map of options.

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.
sourceraw docstring

execute-statementclj

(execute-statement conn statement)
(execute-statement conn statement opt)

Execute a given prepared statement and return a result. The way the result is processed heavily depends on options.

Execute a given prepared statement and return a result.
The way the result is processed heavily depends on options.
sourceraw docstring

get-error-fieldscljdeprecated

(get-error-fields e)

Get a map of error fields from an instance of PGErrorResponse. Deprecated, use ex-data instead.

Get a map of error fields from an instance of
`PGErrorResponse`. **Deprecated**, use `ex-data`
instead.
sourceraw docstring

get-parameterclj

(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.
sourceraw docstring

get-parametersclj

(get-parameters conn)

Return a {String->String} map of all the connection parameters.

Return a {String->String} map of all the connection parameters.
sourceraw docstring

idclj

(id src)

Get a unique ID of this source (a Connection or a Pool).

Get a unique ID of this source (a Connection or a Pool).
sourceraw docstring

idle?clj

(idle? conn)

True if the connection is in the IDLE state.

True if the connection is in the IDLE state.
sourceraw docstring

in-transaction?clj

(in-transaction? conn)

True if the connection is in TRANSACTION at the moment.

True if the connection is in TRANSACTION at the moment.
sourceraw docstring

is-ssl?clj

(is-ssl? conn)

True if the Connection is SSL-encrypted.

True if the Connection is SSL-encrypted.
sourceraw docstring

json-wrapclj

(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.
sourceraw docstring

listenclj

(listen conn channel)

Subscribe a connection to a given channel.

Subscribe a connection to a given channel.
sourceraw docstring

notifyclj

(notify src channel message)

Send a text message to a given channel.

Send a text message to a given channel.
sourceraw docstring

pidclj

(pid conn)

Get PID of the connection on the server.

Get PID of the connection on the server.
sourceraw docstring

poll-notificationsclj

(poll-notifications conn)

Perform an empty query so that pending notifications get flushed to the client. Doesn't guarantee though they will be sent for sure due to their async nature. The result is a number of notifications got and processed.

Perform an empty query so that pending notifications
get flushed to the client. Doesn't guarantee though they
will be sent for sure due to their async nature. The
result is a number of notifications got and processed.
sourceraw docstring

poolclj

(pool src)
(pool host port user password database)

Run a new Pool from a config map or a URI.

Run a new Pool from a config map or a URI.
sourceraw docstring

pool?clj

(pool? x)

True if a value is a Pool instance.

True if a value is a Pool instance.
sourceraw docstring

prepareclj

(prepare conn sql)
(prepare conn sql opt)

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.

Must be called against a Connection object since prepared statements cannot be shared across multiple connections.

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.

Must be called against a Connection object since prepared
statements cannot be shared across multiple connections.
sourceraw docstring

prepared-statement?clj

(prepared-statement? x)

True if it's an instance of the PreparedStatement class.

True if it's an instance of the PreparedStatement class.
sourceraw docstring

queryclj

(query src sql)
(query src sql opt)

Run a SQL expression WITH NO parameters. The result is always sent back in text mode (binary mode doesn't work with the QUERY API). Arguments:

  • src is a data source (a Connection, a Pool, a map, a URI string);
  • sql is a SQL string without parameters (e.g. $1, etc);
  • opt is a map of options.
Run a SQL expression WITH NO parameters. The result
is always sent back in text mode (binary mode doesn't
work with the QUERY API). Arguments:
- `src` is a data source (a Connection, a Pool, a map, a URI string);
- `sql` is a SQL string without parameters (e.g. $1, etc);
- `opt` is a map of options.
sourceraw docstring

rollbackclj

(rollback conn)

Rollback the current transaction.

Rollback the current transaction.
sourceraw docstring

set-read-onlyclj

(set-read-only conn)

Set the current transaction read-only.

Set the current transaction read-only.
sourceraw docstring

set-tx-levelclj

(set-tx-level conn level)

Set transaction isolation level for the current transaction.

Set transaction isolation level for the current transaction.
sourceraw docstring

statusclj

(status conn)

Return the current transaction status, one of :I, :T, or :E.

Return the current transaction status, one of :I, :T, or :E.
sourceraw docstring

tx-error?clj

(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.
sourceraw docstring

TX_DEFAULTSclj

source

TX_READ_COMMITTEDclj

source

TX_READ_UNCOMMITTEDclj

source

TX_REPEATABLE_READclj

source

TX_SERIALIZABLEclj

source

unlistenclj

(unlisten conn channel)

Unsubscribe a connection from a given channel.

Unsubscribe a connection from a given channel.
sourceraw docstring

with-conncljmacro

(with-conn [bind src] & body)

Just a shorter version of with-connection.

Just a shorter version of `with-connection`.
sourceraw docstring

with-connectioncljmacro

(with-connection [bind src] & body)

Perform a block of code while the bind symbol is bound to a Connection object. If the src is a config map, the connection gets closed afterwards. When the src is a pool, the connection gets borrowed and returned to the pool without closing. For a connection, nothing happens when exiting the macro.

Perform a block of code while the `bind` symbol is bound
to a `Connection` object. If the `src` is a config map,
the connection gets closed afterwards. When the `src` is
a pool, the connection gets borrowed and returned to the
pool without closing. For a connection, nothing happens
when exiting the macro.
sourceraw docstring

with-lockcljmacro

(with-lock [conn] & body)

Perform a block of code while the connection is locked (no other threads can interfere).

Perform a block of code while the connection is locked
(no other threads can interfere).
sourceraw docstring

with-poolcljmacro

(with-pool [bind config] & body)

Execute the body while the bind symbol is bound to a new Pool instance. Close the pool afterwards.

Execute the body while the `bind` symbol is bound
to a new Pool instance. Close the pool afterwards.
sourceraw docstring

with-statementcljmacro

(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.
sourceraw docstring

with-timeoutcljmacro

(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.
sourceraw docstring

with-transactioncljmacro

(with-transaction [tx src] & body)
(with-transaction [tx src {:keys [isolation-level read-only? rollback?]}]
                  &
                  body)

Obtain a connection from a source and perform a block of code wrapping the connection with a transaction, namely:

  • run BEGIN before the code block;
  • capture all possible exceptions;
  • should an exception was caught, ROLLBACK...
  • and re-throw it;
  • if no exception was caught, COMMIT.

Arguments:

  • tx is a symbol which a transactional connection is bound to;
  • src is a data source (a map, a Pool, a Connection, a URI string).

The third argument is an optional map of parameters:

  • 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.

Nested transactions are consumed by the most outer transaction. For example, you have two nested with-transaction blocks:

(with-transaction [tx1 {...}] ;; 1 (do-this ...) (with-transaction [tx2 tx1] ;; 2 (do-that ...)))

In this case, only the first block will produce BEGIN and COMMIT commands. The second block will expand into the body only:

(pg/begin ...) (do-this ...) (do-that ...) (pg/commit ...)

Obtain a connection from a source and perform a block of code
wrapping the connection with a transaction, namely:

- run BEGIN before the code block;
- capture all possible exceptions;
- should an exception was caught, ROLLBACK...
- and re-throw it;
- if no exception was caught, COMMIT.

Arguments:
- `tx` is a symbol which a transactional connection is bound to;
- `src` is a data source (a map, a Pool, a Connection, a URI string).

The third argument is an optional map of parameters:

- `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.

Nested transactions are consumed by the most outer transaction.
For example, you have two nested `with-transaction` blocks:

(with-transaction [tx1 {...}]          ;; 1
  (do-this ...)
  (with-transaction [tx2 tx1]          ;; 2
    (do-that ...)))

In this case, only the first block will produce `BEGIN` and `COMMIT`
commands. The second block will expand into the body only:

(pg/begin ...)
  (do-this ...)
  (do-that ...)
(pg/commit ...)

sourceraw docstring

with-txcljmacrodeprecated

(with-tx [conn opts] & body)

DEPRECATED: use with-transaction above.

Acts like with-transaction but accepts a connection, not a data source. Thus, no a binding symbol required.

**DEPRECATED**: use `with-transaction` above.
---------------------------------------------
Acts like `with-transaction` but accepts a connection,
not a data source. Thus, no a binding symbol required.
sourceraw docstring

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

× close