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.
(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.
(close-conn conn)Closes a Datalevin connection.
Closes a Datalevin connection.
(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])])
(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")
(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.
(get-db conn-or-db-or-system)Returns the current database value from a connection, db, or system map.
Accepts:
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.
(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")
(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)
(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
(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"})])(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])
(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]])
(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]})(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"}])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 |