Liking cljdoc? Tell your friends :D

biff.datalevin.db

Database connection management, transaction helpers, and query utilities.

Provides Biff-style transaction semantics adapted for Datalevin.

Database connection management, transaction helpers, and query utilities.

Provides Biff-style transaction semantics adapted for Datalevin.
raw docstring

assoc-dbclj

(assoc-db ctx)

Sets :biff/db on the context map to the current database snapshot.

Use this for Biff compatibility or to attach a db value to contexts that may later be passed around without :biff.datalevin/conn.

This matches Biff's assoc-db pattern for compatibility.

Sets :biff/db on the context map to the current database snapshot.

Use this for Biff compatibility or to attach a db value to contexts that
may later be passed around without :biff.datalevin/conn.

This matches Biff's assoc-db pattern for compatibility.
sourceraw docstring

close-connclj

(close-conn conn)

Closes a Datalevin connection.

Closes a Datalevin connection.
sourceraw docstring

conn?clj

(conn? x)
source

delete-txclj

(delete-tx id)

Creates a retraction transaction for an entity.

Example: (submit-tx conn [(delete-tx [:user/id user-id])])

Creates a retraction transaction for an entity.

Example:
  (submit-tx conn [(delete-tx [:user/id user-id])])
sourceraw docstring

entity-exists?clj

(entity-exists? db-or-conn-or-system attr value)

Checks if an entity with the given attribute value exists.

Example: (entity-exists? db :user/email "test@example.com")

Checks if an entity with the given attribute value exists.

Example:
  (entity-exists? db :user/email "test@example.com")
sourceraw docstring

get-connclj

(get-conn db-path)
(get-conn db-path schema)
(get-conn db-path schema opts)

Opens a Datalevin connection.

Args: db-path - Path to the database directory schema - Optional Datalevin schema map opts - Optional map of additional options for d/get-conn

Returns the connection.

Opens a Datalevin connection.

Args:
  db-path - Path to the database directory
  schema  - Optional Datalevin schema map
  opts    - Optional map of additional options for d/get-conn

Returns the connection.
sourceraw docstring

get-dbclj

(get-db conn-or-db-or-system)

Returns the current database value from a connection, db, or system map.

Accepts:

  • A Datalevin connection (Atom) -> calls (d/db conn)
  • A Datalevin database value -> returns as-is
  • A system/context map with :biff.datalevin/conn -> gets the current db value from the connection
  • A system/context map with only :biff/db -> returns the db value (Biff compatibility)

If both :biff.datalevin/conn and :biff/db are present, :biff.datalevin/conn takes precedence.

Returns the current database value from a connection, db, or system map.

Accepts:
  - A Datalevin connection (Atom) -> calls (d/db conn)
  - A Datalevin database value -> returns as-is
  - A system/context map with :biff.datalevin/conn -> gets the current db value from the connection
  - A system/context map with only :biff/db -> returns the db value (Biff compatibility)

If both :biff.datalevin/conn and :biff/db are present, :biff.datalevin/conn
takes precedence.
sourceraw docstring

lookupclj

(lookup db-or-conn-or-system attr value)
(lookup db-or-conn-or-system attr value pull-expr)

Finds a single entity by attribute value.

Returns the entity map or nil if not found.

Example: (lookup db :user/email "test@example.com")

Finds a single entity by attribute value.

Returns the entity map or nil if not found.

Example:
  (lookup db :user/email "test@example.com")
sourceraw docstring

lookup-allclj

(lookup-all db-or-conn-or-system attr value)
(lookup-all db-or-conn-or-system attr value pull-expr)

Finds all entities matching an attribute value.

Returns a vector of entity maps.

Example: (lookup-all db :user/role :admin)

Finds all entities matching an attribute value.

Returns a vector of entity maps.

Example:
  (lookup-all db :user/role :admin)
sourceraw docstring

lookup-idclj

(lookup-id db-or-conn-or-system attr value)

Returns the entity id (:db/id) for an entity with the given attribute value.

Example: (lookup-id db :user/email "test@example.com") ;; => 12345

Returns the entity id (:db/id) for an entity with the given attribute value.

Example:
  (lookup-id db :user/email "test@example.com")
  ;; => 12345
sourceraw docstring

merge-txclj

(merge-tx id attrs)

Creates a transaction that merges attributes into an existing entity. Only updates provided attributes, leaving others unchanged.

Example: (submit-tx conn [(merge-tx [:user/id user-id] {:user/name "New Name"})])

Creates a transaction that merges attributes into an existing entity.
Only updates provided attributes, leaving others unchanged.

Example:
  (submit-tx conn [(merge-tx [:user/id user-id]
                             {:user/name "New Name"})])
sourceraw docstring

pullclj

(pull db-or-conn-or-system pull-expr eid)

Convenience wrapper for d/pull.

Example: (pull db [:user/email :user/name] [:user/id user-id])

Convenience wrapper for d/pull.

Example:
  (pull db [:user/email :user/name] [:user/id user-id])
sourceraw docstring

pull-manyclj

(pull-many db-or-conn-or-system pull-expr eids)

Convenience wrapper for d/pull-many.

Example: (pull-many db [:user/email :user/name] [[:user/id id1] [:user/id id2]])

Convenience wrapper for d/pull-many.

Example:
  (pull-many db [:user/email :user/name] [[:user/id id1] [:user/id id2]])
sourceraw docstring

qclj

(q query db-or-conn-or-system & args)

Convenience wrapper for d/q.

Automatically extracts the database from connection/system if provided. Supports both positional and keyword argument styles.

Examples: (q '[:find ?e :where [?e :user/email]] db) (q {:query '[:find ?e :where [?e :user/email]] :args [db]})

Convenience wrapper for d/q.

Automatically extracts the database from connection/system if provided.
Supports both positional and keyword argument styles.

Examples:
  (q '[:find ?e :where [?e :user/email]] db)
  (q {:query '[:find ?e :where [?e :user/email]]
      :args [db]})
sourceraw docstring

submit-txclj

(submit-tx conn-or-system txs)

Submits a transaction to Datalevin.

Accepts a connection (or system map) and a vector of transaction maps.

Transaction maps support special values: :db/now - Replaced with current Date :db/uuid - Replaced with random UUID

For new entities, include the unique identity attribute(s). For updates, use a lookup ref as :db/id.

Example: ;; Create new entity (unique attr is :user/id) (submit-tx conn [{:user/id user-id :user/email "test@example.com" :user/created-at :db/now}])

;; Update existing entity (submit-tx conn [{:db/id [:user/id user-id] :user/name "New Name"}])

Submits a transaction to Datalevin.

Accepts a connection (or system map) and a vector of transaction maps.

Transaction maps support special values:
  :db/now  - Replaced with current Date
  :db/uuid - Replaced with random UUID

For new entities, include the unique identity attribute(s).
For updates, use a lookup ref as :db/id.

Example:
  ;; Create new entity (unique attr is :user/id)
  (submit-tx conn [{:user/id user-id
                    :user/email "test@example.com"
                    :user/created-at :db/now}])

  ;; Update existing entity
  (submit-tx conn [{:db/id [:user/id user-id]
                    :user/name "New Name"}])
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