Liking cljdoc? Tell your friends :D

libpg-clj.core


add-time-labelcljmacro

(add-time-label p label)

Adds a UUID v1 timestamp label to a map.

Example: (add-time-label {:name "test"} :created-at) ;=> {:name "test" :created-at #uuid "..."}

Adds a UUID v1 timestamp label to a map.

Example:
  (add-time-label {:name "test"} :created-at)
  ;=> {:name "test" :created-at #uuid "..."}
sourceraw docstring

close-poolclj

(close-pool pool)

Closes a connection pool, releasing all resources.

Parameters: pool - A ConnectionPool created by make-pool

Can also use (.close pool) or (with-open [pool (make-pool config)] ...).

Closes a connection pool, releasing all resources.

Parameters:
  pool - A ConnectionPool created by make-pool

Can also use (.close pool) or (with-open [pool (make-pool config)] ...).
sourceraw docstring

convert-enumclj

(convert-enum tk T p)

Converts a field in map p to a [value type] pair for enum casting.

Parameters: tk - The key to convert in the map T - A type map where (get T tk) returns the enum type name p - The map containing the value to convert

Returns the map with tk's value converted to [value type] format, or the original map if tk is not present.

Converts a field in map p to a [value type] pair for enum casting.

Parameters:
  tk - The key to convert in the map
  T  - A type map where (get T tk) returns the enum type name
  p  - The map containing the value to convert

Returns the map with tk's value converted to [value type] format,
or the original map if tk is not present.
sourceraw docstring

drop-fieldscljmacro

(drop-fields p & fields)

Removes specified fields from a map. Convenience wrapper around dissoc.

Example: (drop-fields {:a 1 :b 2 :c 3} :a :c) ;=> {:b 2}

Removes specified fields from a map. Convenience wrapper around dissoc.

Example:
  (drop-fields {:a 1 :b 2 :c 3} :a :c)
  ;=> {:b 2}
sourceraw docstring

explain-enumclj

(explain-enum conn name)

Retrieves all possible values for a PostgreSQL enum type.

Parameters: conn - Database connection or pool name - The enum type name as a string

Returns a vector of enum values as strings.

Retrieves all possible values for a PostgreSQL enum type.

Parameters:
  conn - Database connection or pool
  name - The enum type name as a string

Returns a vector of enum values as strings.
sourceraw docstring

h-castcljmacro

(h-cast value type)

Creates a HoneySQL cast expression.

Example: (h-cast :my-field :integer) ;=> Generates SQL: my_field::integer

Creates a HoneySQL cast expression.

Example:
  (h-cast :my-field :integer)
  ;=> Generates SQL: my_field::integer
sourceraw docstring

jdbc-execclj

(jdbc-exec conn query & [_])

Executes a JDBC query and returns the first result.

Parameters: conn - Database connection or pool query - SQL query vector [sql & params]

Returns the first element of the execute! result (typically row count).

Executes a JDBC query and returns the first result.

Parameters:
  conn  - Database connection or pool
  query - SQL query vector [sql & params]

Returns the first element of the execute! result (typically row count).
sourceraw docstring

json-aggclj

(json-agg inner-select)

Wraps a subquery with JSON aggregation.

Creates a query that aggregates all rows from inner-select into a JSON array.

Parameters: inner-select - A HoneySQL query map

Example: (json-agg {:select [:id :name] :from [:users]}) ;=> {:select [(call :json_agg :x)] :from [[{...} :x]]}

Wraps a subquery with JSON aggregation.

Creates a query that aggregates all rows from inner-select into a JSON array.

Parameters:
  inner-select - A HoneySQL query map

Example:
  (json-agg {:select [:id :name] :from [:users]})
  ;=> {:select [(call :json_agg :x)] :from [[{...} :x]]}
sourceraw docstring

json>clj

(json> field path)
(json> field path type)

JSONB path accessor returning JSON (preserves type).

Uses -> for single key access, #> for path (vector) access.

Parameters: field - The JSONB column name path - Key (keyword) or path (vector of keywords) type - Optional: cast result to this type

Examples: (json> :data :name) ; data::jsonb->'name' (json> :data [:user :name]) ; data::jsonb#>'{user,name}' (json> :data :age :integer) ; (data::jsonb->'age')::integer

JSONB path accessor returning JSON (preserves type).

Uses -> for single key access, #> for path (vector) access.

Parameters:
  field - The JSONB column name
  path  - Key (keyword) or path (vector of keywords)
  type  - Optional: cast result to this type

Examples:
  (json> :data :name)           ; data::jsonb->'name'
  (json> :data [:user :name])   ; data::jsonb#>'{user,name}'
  (json> :data :age :integer)   ; (data::jsonb->'age')::integer
sourceraw docstring

json>>clj

(json>> field path)
(json>> field path type)

JSONB path accessor returning text (always string).

Uses ->> for single key access, #>> for path (vector) access.

Parameters: field - The JSONB column name path - Key (keyword) or path (vector of keywords) type - Optional: cast result to this type

Examples: (json>> :data :name) ; data::jsonb->>'name' (json>> :data [:user :name]) ; data::jsonb#>>'{user,name}' (json>> :data :age :integer) ; (data::jsonb->>'age')::integer

JSONB path accessor returning text (always string).

Uses ->> for single key access, #>> for path (vector) access.

Parameters:
  field - The JSONB column name
  path  - Key (keyword) or path (vector of keywords)
  type  - Optional: cast result to this type

Examples:
  (json>> :data :name)           ; data::jsonb->>'name'
  (json>> :data [:user :name])   ; data::jsonb#>>'{user,name}'
  (json>> :data :age :integer)   ; (data::jsonb->>'age')::integer
sourceraw docstring

kw->pgenumclj

(kw->pgenum kw)

Converts a namespaced keyword to a PostgreSQL enum PGobject.

The keyword namespace becomes the enum type (with - replaced by _), and the keyword name becomes the enum value.

Example: (kw->pgenum :user-status/active) ;=> PGobject with type="user_status" value="active"

Converts a namespaced keyword to a PostgreSQL enum PGobject.

The keyword namespace becomes the enum type (with - replaced by _),
and the keyword name becomes the enum value.

Example:
  (kw->pgenum :user-status/active)
  ;=> PGobject with type="user_status" value="active"
sourceraw docstring

make-poolclj

(make-pool config)

Creates a c3p0 connection pool for PostgreSQL.

Config map keys: :classname - JDBC driver class (e.g., "org.postgresql.Driver") :subprotocol - Database subprotocol (e.g., "postgresql") :subname - Database subname (e.g., "//localhost:5432/mydb") :user - Database username :password - Database password :min-pool - Minimum/initial pool size :max-pool - Maximum pool size :prepare-threshold - PreparedStatement threshold (default 0)

Returns a ConnectionPool record (implements Closeable) with :datasource key, suitable for use with clojure.java.jdbc and with-open.

Example: (with-open [pool (make-pool config)] (jdbc/query pool ["SELECT 1"]))

Creates a c3p0 connection pool for PostgreSQL.

Config map keys:
  :classname         - JDBC driver class (e.g., "org.postgresql.Driver")
  :subprotocol       - Database subprotocol (e.g., "postgresql")
  :subname           - Database subname (e.g., "//localhost:5432/mydb")
  :user              - Database username
  :password          - Database password
  :min-pool          - Minimum/initial pool size
  :max-pool          - Maximum pool size
  :prepare-threshold - PreparedStatement threshold (default 0)

Returns a ConnectionPool record (implements Closeable) with :datasource key,
suitable for use with clojure.java.jdbc and with-open.

Example:
  (with-open [pool (make-pool config)]
    (jdbc/query pool ["SELECT 1"]))
sourceraw docstring

totalclj

A raw SQL expression for counting total rows using a window function. Useful for pagination queries to get total count alongside results.

Usage in HoneySQL: {:select [:id :name total] :from [:users]}

A raw SQL expression for counting total rows using a window function.
Useful for pagination queries to get total count alongside results.

Usage in HoneySQL:
  {:select [:id :name total] :from [:users]}
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close