CREATE DATABASE / DROP DATABASE token-driven parser plus the
db-from-template helper used to wire a server-level config
template to a per-database config.
JSqlParser 5.x has no AST class for either statement (returns
UnsupportedStatement), so we hand-parse before JSqlParser sees
the SQL. The grammar accepted is:
CREATE DATABASE name [WITH] [(] [k [=] v [,]]* [)] DROP DATABASE [IF EXISTS] name [WITH (FORCE)]
name is either a bare identifier or a quoted identifier
("..."). Option values are 'string', "ident", number,
true|false, or a bare identifier.
Datahike-aware option keys are translated into datahike config:
BACKEND -> [:store :backend] keyword STORE_ID -> [:store :id] string PATH -> [:store :path] string (file backend) HOST / PORT / USER / -> [:store :*] string|long PASSWORD / DBNAME (pg backend) SCHEMA_FLEXIBILITY -> :schema-flexibility keyword KEEP_HISTORY -> :keep-history? boolean INDEX -> :index :datahike.index/<value>
PostgreSQL-only option keys (OWNER, TEMPLATE, ENCODING, LC_COLLATE, LC_CTYPE, LOCALE, LOCALE_PROVIDER, ICU_LOCALE, ICU_RULES, COLLATION_VERSION, TABLESPACE, ALLOW_CONNECTIONS, CONNECTION_LIMIT, IS_TEMPLATE, OID, STRATEGY, REFRESH_COLLATION_VERSION) are silently accepted with a NOTICE so pg_dump output round-trips.
Unknown option names raise :syntax-error.
CREATE DATABASE / DROP DATABASE token-driven parser plus the
`db-from-template` helper used to wire a server-level config
template to a per-database config.
JSqlParser 5.x has no AST class for either statement (returns
`UnsupportedStatement`), so we hand-parse before JSqlParser sees
the SQL. The grammar accepted is:
CREATE DATABASE name [WITH] [(] [k [=] v [,]]* [)]
DROP DATABASE [IF EXISTS] name [WITH (FORCE)]
`name` is either a bare identifier or a quoted identifier
("..."). Option values are 'string', "ident", number,
true|false, or a bare identifier.
Datahike-aware option keys are translated into datahike config:
BACKEND -> [:store :backend] keyword
STORE_ID -> [:store :id] string
PATH -> [:store :path] string (file backend)
HOST / PORT / USER / -> [:store :*] string|long
PASSWORD / DBNAME (pg backend)
SCHEMA_FLEXIBILITY -> :schema-flexibility keyword
KEEP_HISTORY -> :keep-history? boolean
INDEX -> :index :datahike.index/<value>
PostgreSQL-only option keys (OWNER, TEMPLATE, ENCODING, LC_COLLATE,
LC_CTYPE, LOCALE, LOCALE_PROVIDER, ICU_LOCALE, ICU_RULES,
COLLATION_VERSION, TABLESPACE, ALLOW_CONNECTIONS, CONNECTION_LIMIT,
IS_TEMPLATE, OID, STRATEGY, REFRESH_COLLATION_VERSION) are silently
accepted with a NOTICE so pg_dump output round-trips.
Unknown option names raise `:syntax-error`.(db-delete-from-template server-template)Build an :on-delete-database hook that mirrors db-from-template.
Releases the conn and best-effort deletes the backing store; the
template is consulted for the storage backend so file/pg/etc.
stores get the right delete call.
Build an `:on-delete-database` hook that mirrors `db-from-template`. Releases the conn and best-effort deletes the backing store; the template is consulted for the storage backend so file/pg/etc. stores get the right delete call.
(db-from-template server-template)Build an :on-create-database hook from a server-level config
template. The returned fn receives [db-name parsed-options],
merges options over the template, interpolates {{name}},
ensures a UUID :id, then runs d/create-database and
d/connect and returns the connection.
Example template: {:store {:backend :memory} :schema-flexibility :write :keep-history? false}
With {{name}} interpolation:
{:store {:backend :file :path "/var/lib/dh/{{name}}"}
:schema-flexibility :write}
Build an `:on-create-database` hook from a server-level config
template. The returned fn receives `[db-name parsed-options]`,
merges options over the template, interpolates `{{name}}`,
ensures a UUID `:id`, then runs `d/create-database` and
`d/connect` and returns the connection.
Example template:
{:store {:backend :memory}
:schema-flexibility :write
:keep-history? false}
With `{{name}}` interpolation:
{:store {:backend :file :path "/var/lib/dh/{{name}}"}
:schema-flexibility :write}(options->config server-template options)Apply parsed options on top of server-template. Returns
{:config datahike-config :notices [str ...]}.
Throws :syntax-error on an unknown non-pg option.
Apply parsed options on top of `server-template`. Returns
{:config datahike-config :notices [str ...]}.
Throws `:syntax-error` on an unknown non-pg option.(parse-create-database toks)Parse a tokenised CREATE DATABASE statement. Returns: {:db-name str :if-not-exists? bool :options [[lower-case-key value] ...]}
The grammar is intentionally lenient — WITH is optional, (...)
is optional, = between key and value is optional, , between
pairs is optional. Each option value is decoded as the right
Clojure type (string for 'literal', long for digits, boolean for
true/false, raw string otherwise).
Parse a tokenised CREATE DATABASE statement. Returns:
{:db-name str
:if-not-exists? bool
:options [[lower-case-key value] ...]}
The grammar is intentionally lenient — `WITH` is optional, `(...)`
is optional, `=` between key and value is optional, `,` between
pairs is optional. Each option value is decoded as the right
Clojure type (string for 'literal', long for digits, boolean for
true/false, raw string otherwise).(parse-drop-database toks)Parse a tokenised DROP DATABASE statement. Returns: {:db-name str :if-exists? bool}
WITH (FORCE) is silently accepted but ignored — Datahike
connections are released as part of the drop regardless.
Parse a tokenised DROP DATABASE statement. Returns:
{:db-name str :if-exists? bool}
`WITH (FORCE)` is silently accepted but ignored — Datahike
connections are released as part of the drop regardless.(tokenize sql)Tokenize a SQL string into a vector of [kind text-or-value] pairs. Tokens: :ident :string :num :bool :eq :comma :lparen :rparen :semicolon.
Tokenize a SQL string into a vector of [kind text-or-value] pairs. Tokens: :ident :string :num :bool :eq :comma :lparen :rparen :semicolon.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |