Liking cljdoc? Tell your friends :D

us.whitford.fulcro.rad.database-adapters.datalevin.start-databases

Database lifecycle management for Datalevin adapter.

Database lifecycle management for Datalevin adapter.
raw docstring

automatic-schemaclj

(automatic-schema schema-name attributes)

Generate a Datalevin schema map from RAD attributes.

Arguments:

  • schema-name: keyword identifying the schema (e.g., :production, :main)
  • attributes: collection of RAD attribute maps

Attributes with ::dlo/native-id? true are skipped since they use the built-in :db/id.

Returns a map suitable for passing to datalevin's get-conn.

Generate a Datalevin schema map from RAD attributes.

Arguments:
- schema-name: keyword identifying the schema (e.g., :production, :main)
- attributes: collection of RAD attribute maps

Attributes with `::dlo/native-id? true` are skipped since they use the built-in :db/id.

Returns a map suitable for passing to datalevin's get-conn.
sourceraw docstring

ensure-schema!clj

(ensure-schema! conn schema)

Ensure the database has the correct schema. If the connection already exists, attempts to update the schema.

Arguments:

  • conn: existing Datalevin connection
  • schema: map of attribute schemas

Throws on incompatible schema changes.

Ensure the database has the correct schema.
If the connection already exists, attempts to update the schema.

Arguments:
- conn: existing Datalevin connection
- schema: map of attribute schemas

Throws on incompatible schema changes.
sourceraw docstring

schema-problemsclj

(schema-problems conn schema-name attributes)

Compare the RAD-derived expected schema for schema-name against the live Datalevin schema of conn, returning a (possibly empty) sequence of problem maps.

Each problem is one of:

  • {:attribute k :problem :missing :expected {...}} the attribute is expected but absent from the database schema
  • {:attribute k :problem :mismatch :key kk :expected e :actual a} a managed property differs from what the database has

Only the adapter-managed keys (:db/valueType, :db/cardinality, :db/unique) are compared, and only when present in the expected schema, so database defaults and internal keys (e.g. :db/aid) do not produce false positives.

Compare the RAD-derived expected schema for `schema-name` against the live
Datalevin schema of `conn`, returning a (possibly empty) sequence of problem
maps.

Each problem is one of:
- `{:attribute k :problem :missing  :expected {...}}`
    the attribute is expected but absent from the database schema
- `{:attribute k :problem :mismatch :key kk :expected e :actual a}`
    a managed property differs from what the database has

Only the adapter-managed keys (`:db/valueType`, `:db/cardinality`,
`:db/unique`) are compared, and only when present in the expected schema, so
database defaults and internal keys (e.g. `:db/aid`) do not produce false
positives.
sourceraw docstring

search-conn-optsclj

(search-conn-opts schema-name attributes)

Extract search domain options from full-text RAD attributes (::dlo/fulltext?) for passing to d/get-conn. Returns {:search-domains {"domain" {...}}} or nil.

Only domains that have actual options (e.g. an attribute declared ::dlo/fulltext? {:index-position? true}) are emitted — Datalevin creates default-configured domains from the schema on its own. When several attributes share a domain their option maps are merged in attribute order.

Domain naming mirrors the schema derivation in attr->schema: the attribute's namespace, unless ::dlo/attribute-schema specifies :db.fulltext/domains (those domains are used) or :db.fulltext/autoDomain (domain is the qualified key without the leading colon).

Extract search domain options from full-text RAD attributes (::dlo/fulltext?)
for passing to d/get-conn. Returns {:search-domains {"domain" {...}}} or nil.

Only domains that have actual options (e.g. an attribute declared
`::dlo/fulltext? {:index-position? true}`) are emitted — Datalevin creates
default-configured domains from the schema on its own. When several
attributes share a domain their option maps are merged in attribute order.

Domain naming mirrors the schema derivation in attr->schema: the attribute's
namespace, unless ::dlo/attribute-schema specifies :db.fulltext/domains
(those domains are used) or :db.fulltext/autoDomain (domain is the qualified
key without the leading colon).
sourceraw docstring

start-database!clj

(start-database! {:keys [path schema attributes auto-schema? conn-opts]
                  :or {auto-schema? true}})

Start a Datalevin database connection.

Arguments:

  • config: map containing:
    • :path - directory path for database storage
    • :schema - RAD schema name (keyword)
    • :attributes - collection of RAD attributes
    • :auto-schema? - if true, automatically create schema from attributes (default true)
    • :conn-opts - (optional) a map of native Datalevin get-conn options to enable v1.0 features, e.g. {:auto-entity-time? true ; maintain :db/created-at / :db/updated-at :validate-data? true ; validate value types on transaction :closed-schema? true ; reject attributes not in the schema :wal? true ; enable WAL mode :search-domains {...}} ; full-text search configuration These are merged with the adapter-derived :vector-domains opts.

Returns a Datalevin connection.

For :vec attributes with :db.vec/dimensions in their dlo/attribute-schema, the vector domain options (including :dimensions) are passed to d/get-conn as :vector-domains connection opts so Datalevin can initialize the HNSW index.

For full-text attributes (::dlo/fulltext?) declared with an options map (e.g. {:index-position? true}), the per-domain options are passed to d/get-conn as :search-domains connection opts. See search-conn-opts.

Start a Datalevin database connection.

Arguments:
- config: map containing:
  - :path - directory path for database storage
  - :schema - RAD schema name (keyword)
  - :attributes - collection of RAD attributes
  - :auto-schema? - if true, automatically create schema from attributes (default true)
  - :conn-opts - (optional) a map of native Datalevin `get-conn` options to
    enable v1.0 features, e.g.
    `{:auto-entity-time? true   ; maintain :db/created-at / :db/updated-at
      :validate-data?    true   ; validate value types on transaction
      :closed-schema?    true   ; reject attributes not in the schema
      :wal?              true   ; enable WAL mode
      :search-domains    {...}} ; full-text search configuration`
    These are merged with the adapter-derived :vector-domains opts.

Returns a Datalevin connection.

For :vec attributes with :db.vec/dimensions in their dlo/attribute-schema,
the vector domain options (including :dimensions) are passed to d/get-conn
as :vector-domains connection opts so Datalevin can initialize the HNSW index.

For full-text attributes (::dlo/fulltext?) declared with an options map
(e.g. {:index-position? true}), the per-domain options are passed to
d/get-conn as :search-domains connection opts. See search-conn-opts.
sourceraw docstring

start-databasesclj

(start-databases config)
(start-databases config {:keys [attributes]})

Start all of the databases described in config, using the schemas defined in attributes.

Arguments:

  • config: a map that contains the key dlo/databases.

The dlo/databases entry in the config is a map with the following form:

{::dlo/databases
 {:production {:path "data/production"
               :auto-schema? true
               :conn-opts {:auto-entity-time? true}}
  :test       {:path "data/test"
               :auto-schema? true}}}

where the key (i.e. :production) is a schema name and the value is a config map containing:

  • :path - directory path for database storage

  • :auto-schema? - if true, automatically generate schema from attributes (default true)

  • :conn-opts - (optional) native Datalevin get-conn options (e.g. :auto-entity-time?, :validate-data?, :closed-schema?, :wal?, :search-domains). See start-database!.

  • options: a map that contains:

    • :attributes - collection of all RAD attributes

Returns a map whose keys are the schema names (i.e. :production) and whose values are the live database connections.

Start all of the databases described in config, using the schemas defined in attributes.

Arguments:
- config: a map that contains the key `dlo/databases`.

The `dlo/databases` entry in the config is a map with the following form:

```
{::dlo/databases
 {:production {:path "data/production"
               :auto-schema? true
               :conn-opts {:auto-entity-time? true}}
  :test       {:path "data/test"
               :auto-schema? true}}}
```

where the key (i.e. `:production`) is a schema name and the value is a config map
containing:
- :path - directory path for database storage
- :auto-schema? - if true, automatically generate schema from attributes (default true)
- :conn-opts - (optional) native Datalevin get-conn options (e.g.
  :auto-entity-time?, :validate-data?, :closed-schema?, :wal?,
  :search-domains). See `start-database!`.

- options: a map that contains:
  - :attributes - collection of all RAD attributes
  
Returns a map whose keys are the schema names (i.e. `:production`) and whose
values are the live database connections.
sourceraw docstring

stop-database!clj

(stop-database! conn)

Close a Datalevin database connection.

Close a Datalevin database connection.
sourceraw docstring

stop-databasesclj

(stop-databases connections)

Stop all database connections.

Arguments:

  • connections: map of schema name -> connection (as returned by start-databases)
Stop all database connections.

Arguments:
- connections: map of schema name -> connection (as returned by start-databases)
sourceraw docstring

type-mapclj

Map from RAD attribute types to Datalevin value types

Map from RAD attribute types to Datalevin value types
sourceraw docstring

vec-conn-optsclj

(vec-conn-opts schema-name attributes)

Extract vector domain options from :vec RAD attributes for passing to d/get-conn. Returns {:vector-domains {"domain_name" {:dimensions N ...}}} or nil.

Datalevin's d/get-conn accepts :vector-domains as a top-level option: per-domain opts (including :dimensions) that override the defaults. The schema attribute's :db.vec/domains just names which domain(s) an attribute belongs to — the actual vector index config lives here.

Extract vector domain options from :vec RAD attributes for passing to d/get-conn.
Returns {:vector-domains {"domain_name" {:dimensions N ...}}} or nil.

Datalevin's d/get-conn accepts :vector-domains as a top-level option:
per-domain opts (including :dimensions) that override the defaults.
The schema attribute's :db.vec/domains just names which domain(s) an
attribute belongs to — the actual vector index config lives here.
sourceraw docstring

verify-schema!clj

(verify-schema! conn schema-name attributes)

Throw when the live Datalevin schema of conn does not satisfy the RAD-derived expected schema for schema-name. Returns true when there are no problems. See schema-problems for the problem shape.

Throw when the live Datalevin schema of `conn` does not satisfy the
RAD-derived expected schema for `schema-name`. Returns `true` when there are
no problems. See `schema-problems` for the problem shape.
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