Liking cljdoc? Tell your friends :D

datahike.pg.schema

Derives virtual PostgreSQL table definitions from Datahike schemas.

Maps attribute namespace prefixes to table names and attribute local names to column names. For example: :person/name → table 'person', column 'name' :person/age → table 'person', column 'age'

Every virtual table gets an implicit 'db_id' column (the entity ID).

Derives virtual PostgreSQL table definitions from Datahike schemas.

Maps attribute namespace prefixes to table names and attribute local names
to column names. For example:
  :person/name  → table 'person', column 'name'
  :person/age   → table 'person', column 'age'

Every virtual table gets an implicit 'db_id' column (the entity ID).
raw docstring

column-attnumclj

(column-attnum schema table-name col-name)

Return the 1-based PG attnum for a column, given the derived virtual-table map. The ordering MUST match pg_attribute row emission and RowDescription emission or pgjdbc's field-metadata JOIN (keyed on (tableOid, attnum)) won't resolve columns — so both sites call this helper.

Returns nil when the table or column isn't known.

Return the 1-based PG attnum for a column, given the derived
virtual-table map. The ordering MUST match pg_attribute row
emission and RowDescription emission or pgjdbc's field-metadata
JOIN (keyed on (tableOid, attnum)) won't resolve columns — so both
sites call this helper.

Returns nil when the table or column isn't known.
raw docstring

column-infoclj

(column-info schema table-name)
(column-info schema table-name db)

Return ordered column info for a specific table, prepending db_id. When db is provided, columns are ordered by schema entity ID (CREATE TABLE order) and :datahike.pg/* hints (column rename, hide, FK target) are applied to the derivation. Returns [{:name str :attr keyword :oid int ...} ...]

Return ordered column info for a specific table, prepending db_id.
When db is provided, columns are ordered by schema entity ID
(CREATE TABLE order) and :datahike.pg/* hints (column rename, hide,
FK target) are applied to the derivation.
Returns [{:name str :attr keyword :oid int ...} ...]
raw docstring

column-order-from-dbclj

(column-order-from-db db table-name)

Derive column creation order for a table from schema entity IDs. Returns [col-name ...] in the order attributes were transacted (CREATE TABLE order). Requires a Datahike db value. Falls back to alphabetical if db is nil.

Derive column creation order for a table from schema entity IDs.
Returns [col-name ...] in the order attributes were transacted (CREATE TABLE order).
Requires a Datahike db value. Falls back to alphabetical if db is nil.
raw docstring

derive-virtual-tablesclj

(derive-virtual-tables schema)
(derive-virtual-tables schema hints)

Derive virtual table definitions from a Datahike schema map.

Returns a map of table-name → {:columns [...] :attrs {...}} where each column is {:name str :attr keyword :oid int :valuetype keyword :cardinality keyword :unique keyword-or-nil :ref? bool :references keyword-or-nil} and :attrs maps column-name → attribute-ident.

Filters out internal (db.*) attributes by default.

When hints is supplied (a map {attr-ident → hint-map} typically built by schema-hints), applies per-attribute customizations:

  • :datahike.pg/hidden true → attribute excluded entirely
  • :datahike.pg/column "x" → column renamed to "x"
  • :datahike.pg/references K→ carried through on the col as :references for the translator's FK-via-ref JOIN rewrite.
Derive virtual table definitions from a Datahike schema map.

Returns a map of table-name → {:columns [...] :attrs {...}}
where each column is {:name str :attr keyword :oid int :valuetype keyword
                      :cardinality keyword :unique keyword-or-nil :ref? bool
                      :references keyword-or-nil}
and :attrs maps column-name → attribute-ident.

Filters out internal (db.*) attributes by default.

When `hints` is supplied (a map `{attr-ident → hint-map}` typically
built by `schema-hints`), applies per-attribute customizations:
- `:datahike.pg/hidden true`  → attribute excluded entirely
- `:datahike.pg/column "x"` → column renamed to "x"
- `:datahike.pg/references K`→ carried through on the col as `:references`
  for the translator's FK-via-ref JOIN rewrite.
raw docstring

ensure-hint-schema!clj

(ensure-hint-schema! conn)

Idempotently install the :datahike.pg/* hint schema attrs on conn. Safe to call multiple times. Called automatically by set-hint! and by the server's ensure-pg-schema!. Exposed as public so callers running under :schema-flexibility :read can prime the schema before their first set-hint! or eager hint transaction.

Idempotently install the :datahike.pg/* hint schema attrs on `conn`.
Safe to call multiple times. Called automatically by `set-hint!` and
by the server's `ensure-pg-schema!`. Exposed as public so callers
running under `:schema-flexibility :read` can prime the schema
before their first `set-hint!` or eager hint transaction.
raw docstring

first-user-oidclj


hint-schemaclj

Datahike schema for the :datahike.pg/* hint entities. A hint is a dedicated entity (NOT attributes attached to the ident) that points at its target via :datahike.pg/for-ident. This sidesteps Datahike's schema-update guard, which forbids adding arbitrary attrs to an already-transacted schema entity — a necessary limit on real schema migration but one that makes ident-attached annotations impractical.

ensure-pg-schema! in server.clj installs this for every handler- backed conn. Users can also transact it eagerly under :schema-flexibility :read.

Datahike schema for the :datahike.pg/* hint entities. A hint is a
dedicated entity (NOT attributes attached to the ident) that points at
its target via :datahike.pg/for-ident. This sidesteps Datahike's
schema-update guard, which forbids adding arbitrary attrs to an
already-transacted schema entity — a necessary limit on real schema
migration but one that makes ident-attached annotations impractical.

`ensure-pg-schema!` in server.clj installs this for every handler-
backed conn. Users can also transact it eagerly under
`:schema-flexibility :read`.
raw docstring

information-schema-columns-rowsclj

(information-schema-columns-rows schema)
(information-schema-columns-rows schema db-or-hints)

Return rows for information_schema.columns query. Each row: [table_catalog table_schema table_name column_name ordinal_position data_type is_nullable column_default].

Accepts an optional db (or hints map) so :datahike.pg/column / :datahike.pg/hidden are applied to the emitted row set. Callers that don't have a db in scope can keep the 1-arity form.

Return rows for information_schema.columns query.
Each row: [table_catalog table_schema table_name column_name ordinal_position
           data_type is_nullable column_default].

Accepts an optional `db` (or `hints` map) so :datahike.pg/column /
:datahike.pg/hidden are applied to the emitted row set. Callers that
don't have a db in scope can keep the 1-arity form.
raw docstring

next-table-oidclj

(next-table-oid db)

Pick the next unused :pg/table-oid. We query via Datalog because the attribute is attached to the row-marker entity, not part of the :schema map.

Pick the next unused :pg/table-oid. We query via Datalog because the
attribute is attached to the row-marker entity, not part of the
:schema map.
raw docstring

oid-for-valuetypeclj

(oid-for-valuetype vtype)

Return the PostgreSQL type OID for a Datahike valueType keyword.

Return the PostgreSQL type OID for a Datahike valueType keyword.
raw docstring

pg-type-nameclj

(pg-type-name vtype)

Return the PostgreSQL type name string for a Datahike valueType keyword.

Return the PostgreSQL type name string for a Datahike valueType keyword.
raw docstring

row-marker-attrclj

(row-marker-attr table-name)

Return the row-existence marker attribute for a table. E.g., :person/db-row-exists for table 'person'.

Return the row-existence marker attribute for a table.
E.g., :person/db-row-exists for table 'person'.
raw docstring

row-marker-colclj


schema-hintsclj

(schema-hints db)

Return {attr-ident → {:column str? :hidden bool? :references kw? :table str?}} by scanning the db for :datahike.pg/for-ident-rooted hint entities. Nil-safe: returns an empty map when db is nil (pure-schema call sites).

Return `{attr-ident → {:column str? :hidden bool? :references kw? :table str?}}`
by scanning the db for :datahike.pg/for-ident-rooted hint entities.
Nil-safe: returns an empty map when `db` is nil (pure-schema call sites).
raw docstring

set-hint!clj

(set-hint! conn target hint)

Convenience: transact or upsert one hint entity. target is the attribute ident the hint applies to (e.g. :widget/full_name). hint is a map of :column / :hidden / :references / :table. Idempotent — :datahike.pg/for-ident is :db.unique/identity, so repeated calls upsert the same hint entity. Ensures the hint schema is installed first so callers needn't pre-install.

Convenience: transact or upsert one hint entity. `target` is the
attribute ident the hint applies to (e.g. `:widget/full_name`).
`hint` is a map of `:column` / `:hidden` / `:references` / `:table`.
Idempotent — `:datahike.pg/for-ident` is :db.unique/identity, so
repeated calls upsert the same hint entity. Ensures the hint schema
is installed first so callers needn't pre-install.
raw docstring

table-namesclj

(table-names schema)

Return sorted list of virtual table names for a schema.

Return sorted list of virtual table names for a schema.
raw docstring

table-oidclj

(table-oid db table-name)

The :pg/table-oid attached to this table's row-marker entity, or nil if the table doesn't exist yet or was created before we started allocating OIDs. Datahike's (:schema db) only surfaces schema-level attrs (:db/valueType etc.); custom attrs on the ident entity require a Datalog lookup against the db.

The :pg/table-oid attached to this table's row-marker entity, or nil
if the table doesn't exist yet or was created before we started
allocating OIDs. Datahike's `(:schema db)` only surfaces schema-level
attrs (:db/valueType etc.); custom attrs on the ident entity require
a Datalog lookup against the db.
raw 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