Persistence facade: backend registry, connection lifecycle, and every
delegated store-*/db-* fn.
Extensions register backend adapters through :ext/persistance. The
facade dispatches each delegated call by resolving the matching var on
the chosen backend namespace ((ns-resolve ns-sym 'db-store-iteration!)
etc.) and applying it to the original args. This keeps the facade
dialect-agnostic - every migration runner / driver-specific oddity stays
inside the backend adapter.
Frontends still call db-error->user-message here, but the actual
translation is offered by backend adapters. Same for store-staleness
checks used by the process-wide shared connection.
Persistence facade: backend registry, connection lifecycle, and every delegated `store-*`/`db-*` fn. Extensions register backend adapters through `:ext/persistance`. The facade dispatches each delegated call by resolving the matching var on the chosen backend namespace (`(ns-resolve ns-sym 'db-store-iteration!)` etc.) and applying it to the original args. This keeps the facade dialect-agnostic - every migration runner / driver-specific oddity stays inside the backend adapter. Frontends still call `db-error->user-message` here, but the actual translation is offered by backend adapters. Same for store-staleness checks used by the process-wide shared connection.
(->kw v)Keyword/string -> TEXT, stripping the leading colon. Nil -> nil.
Keyword/string -> TEXT, stripping the leading colon. Nil -> nil.
(->ref v)Normalize an entity reference to a string ID for SQL. Accepts: UUID, string, or nil. Returns string or nil.
The ONLY way to extract a SQL-ready string from an entity reference -- pass the plain UUID or string directly.
Normalize an entity reference to a string ID for SQL. Accepts: UUID, string, or nil. Returns string or nil. The ONLY way to extract a SQL-ready string from an entity reference -- pass the plain UUID or string directly.
(db-create-connection! db-spec)Open a persistence connection from db-spec.
Common spec forms: nil - no DB (returns nil) :memory - in-memory ephemeral store (backend-defined) "path/to.db" - file-backed store (backend-defined) {:backend :sqlite :path ...} - explicit backend selection {:backend :sqlite :datasource ds} - caller-owned DataSource
With a single registered backend, omitting :backend works and the
facade tags the returned store map with the chosen backend so all
subsequent facade calls dispatch correctly.
Triggers manifest/scan-extensions! on first call so a freshly
started JVM with no extensions yet required has a chance to load
any backend-providing namespaces from the classpath.
Open a persistence connection from `db-spec`.
Common spec forms:
nil - no DB (returns nil)
:memory - in-memory ephemeral store (backend-defined)
"path/to.db" - file-backed store (backend-defined)
{:backend :sqlite :path ...} - explicit backend selection
{:backend :sqlite :datasource ds} - caller-owned DataSource
With a single registered backend, omitting `:backend` works and the
facade tags the returned store map with the chosen backend so all
subsequent facade calls dispatch correctly.
Triggers `manifest/scan-extensions!` on first call so a freshly
started JVM with no extensions yet required has a chance to load
any backend-providing namespaces from the classpath.(db-dispose-shared-connection!)Close the shared connection if one is open. Idempotent.
Close the shared connection if one is open. Idempotent.
(db-error->user-message e)Translate a persistence exception into something a human can act on.
Backend adapters own backend-specific recognition; unknown errors fall
back to (ex-message e).
Translate a persistence exception into something a human can act on. Backend adapters own backend-specific recognition; unknown errors fall back to `(ex-message e)`.
(db-search db-info query opts)Backend-neutral full-text search facade. Delegates to the registered
persistence backend, which RENDERS the neutral query DSL into its native
full-text query and runs it. No caller passes an engine dialect — only the
DSL in search-query-dsl-doc.
query is the DSL — a string (implicit-AND of its words) or a DSL map.
opts:
:owner-table restrict to one owner table (string)
:field restrict to one indexed field (string)
:limit max hits (backend default applies when nil)
Returns a vector of hits sorted by relevance (best first), each
{:owner-table :owner-id :field :snippet :rank}. Backends MUST honor the
DSL; an engine that cannot express a node should degrade it (e.g. :near ->
:all), never reject well-formed DSL. A MALFORMED query (e.g. a lone :not)
may throw — that is a DSL logic error, distinct from un-matchable content.
Backend-neutral full-text search facade. Delegates to the registered
persistence backend, which RENDERS the neutral query DSL into its native
full-text query and runs it. No caller passes an engine dialect — only the
DSL in `search-query-dsl-doc`.
`query` is the DSL — a string (implicit-AND of its words) or a DSL map.
`opts`:
:owner-table restrict to one owner table (string)
:field restrict to one indexed field (string)
:limit max hits (backend default applies when nil)
Returns a vector of hits sorted by relevance (best first), each
`{:owner-table :owner-id :field :snippet :rank}`. Backends MUST honor the
DSL; an engine that cannot express a node should degrade it (e.g. :near ->
:all), never reject well-formed DSL. A MALFORMED query (e.g. a lone :not)
may throw — that is a DSL logic error, distinct from un-matchable content.(db-session-state-list-for-workspace db-info workspace-id)(db-session-state-set-workspace! db-info session-state-id workspace-id)(db-shared-connection! db-spec)Return the process-wide shared persistence connection for db-spec,
opening it on first call and caching the handle for the lifetime of
the JVM. Subsequent calls return the cached handle regardless of
the db-spec argument - the singleton intentionally pins to the
first spec it saw.
Pair with db-dispose-shared-connection! on process shutdown.
Return the process-wide shared persistence connection for `db-spec`, opening it on first call and caching the handle for the lifetime of the JVM. Subsequent calls return the cached handle regardless of the `db-spec` argument - the singleton intentionally pins to the first spec it saw. Pair with `db-dispose-shared-connection!` on process shutdown.
(db-store-iteration! db-info opts)Same delegating shape as the macro-defined fns, but with input validation kept here so every backend gets the same precondition guarantees for free.
Same delegating shape as the macro-defined fns, but with input validation kept here so every backend gets the same precondition guarantees for free.
(db-workspace-list-by-repo db-info repo-id)(db-workspace-list-by-repo db-info repo-id state-set)(db-workspace-set-filesystem-roots! db-info workspace-id roots)(register-backend! id ns-sym)Register a persistence backend implementation.
id - keyword identity, e.g. :sqlite.
ns-sym - fully qualified namespace symbol that defines the backend
functions (db-open!, db-close!, db-log!, every
store-*/db-* fn used by this facade). Vars are
resolved lazily via ns-resolve so REPL redefinition
just works.
Idempotent on id. Returns id.
Register a persistence backend implementation.
`id` - keyword identity, e.g. `:sqlite`.
`ns-sym` - fully qualified namespace symbol that defines the backend
functions (`db-open!`, `db-close!`, `db-log!`, every
`store-*`/`db-*` fn used by this facade). Vars are
resolved lazily via `ns-resolve` so REPL redefinition
just works.
Idempotent on `id`. Returns `id`.(registered-backends)Map of registered backends keyed by id.
Map of registered backends keyed by id.
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 |