Liking cljdoc? Tell your friends :D

datascript.core


conn-from-datomsclj/s

(conn-from-datoms datoms)
(conn-from-datoms datoms schema)

Creates an empty DB and a mutable reference to it. See create-conn.

Creates an empty DB and a mutable reference to it. See [[create-conn]].
sourceraw docstring

conn-from-dbclj/s

(conn-from-db db)

Creates a mutable reference to a given immutable database. See create-conn.

Creates a mutable reference to a given immutable database. See [[create-conn]].
sourceraw docstring

conn?clj/s

(conn? conn)

Returns true if this is a connection to a DataScript db, false otherwise.

Returns `true` if this is a connection to a DataScript db, `false` otherwise.
sourceraw docstring

create-connclj/s

(create-conn)
(create-conn schema)

Creates a mutable reference (a “connection”) to an empty immutable database.

Connections are lightweight in-memory structures (~atoms) with direct support of transaction listeners (listen!, unlisten!) and other handy DataScript APIs (transact!, reset-conn!, db).

To access underlying immutable DB value, deref: @conn.

Creates a mutable reference (a “connection”) to an empty immutable database.

Connections are lightweight in-memory structures (~atoms) with direct support of transaction listeners ([[listen!]], [[unlisten!]]) and other handy DataScript APIs ([[transact!]], [[reset-conn!]], [[db]]).

To access underlying immutable DB value, deref: `@conn`.
sourceraw docstring

data-readersclj/s

Data readers for EDN readers. In CLJS they’re registered automatically. In CLJ, if data_readers.clj do not work, you can always do

(clojure.edn/read-string {:readers data-readers} "...")
Data readers for EDN readers. In CLJS they’re registered automatically. In CLJ, if `data_readers.clj` do not work, you can always do

```
(clojure.edn/read-string {:readers data-readers} "...")
```
sourceraw docstring

datomclj/s

(datom e a v)
(datom e a v tx)
(datom e a v tx added)

Low-level fn to create raw datoms.

Optionally with transaction id (number) and added flag (true for addition, false for retraction).

See also init-db.

Low-level fn to create raw datoms.

Optionally with transaction id (number) and `added` flag (`true` for addition, `false` for retraction).

See also [[init-db]].
sourceraw docstring

datom?clj/s

(datom? x)

Returns true if the given value is a datom, false otherwise.

Returns `true` if the given value is a datom, `false` otherwise.
sourceraw docstring

datomsclj/s

(datoms db index)
(datoms db index c1)
(datoms db index c1 c2)
(datoms db index c1 c2 c3)
(datoms db index c1 c2 c3 c4)

Index lookup. Returns a sequence of datoms (lazy iterator over actual DB index) which components (e, a, v) match passed arguments.

Datoms are sorted in index sort order. Possible index values are: :eavt, :aevt, :avet.

Usage:

; find all datoms for entity id == 1 (any attrs and values)
; sort by attribute, then value
(datoms db :eavt 1)
; => (#datascript/Datom [1 :friends 2]
;     #datascript/Datom [1 :likes "fries"]
;     #datascript/Datom [1 :likes "pizza"]
;     #datascript/Datom [1 :name "Ivan"])

; find all datoms for entity id == 1 and attribute == :likes (any values)
; sorted by value
(datoms db :eavt 1 :likes)
; => (#datascript/Datom [1 :likes "fries"]
;     #datascript/Datom [1 :likes "pizza"])

; find all datoms for entity id == 1, attribute == :likes and value == "pizza"
(datoms db :eavt 1 :likes "pizza")
; => (#datascript/Datom [1 :likes "pizza"])

; find all datoms for attribute == :likes (any entity ids and values)
; sorted by entity id, then value
(datoms db :aevt :likes)
; => (#datascript/Datom [1 :likes "fries"]
;     #datascript/Datom [1 :likes "pizza"]
;     #datascript/Datom [2 :likes "candy"]
;     #datascript/Datom [2 :likes "pie"]
;     #datascript/Datom [2 :likes "pizza"])

; find all datoms that have attribute == `:likes` and value == `"pizza"` (any entity id)
; `:likes` must be a unique attr, reference or marked as `:db/index true`
(datoms db :avet :likes "pizza")
; => (#datascript/Datom [1 :likes "pizza"]
;     #datascript/Datom [2 :likes "pizza"])

; find all datoms sorted by entity id, then attribute, then value
(datoms db :eavt) ; => (...)

Useful patterns:

; get all values of :db.cardinality/many attribute
(->> (datoms db :eavt eid attr) (map :v))

; lookup entity ids by attribute value
(->> (datoms db :avet attr value) (map :e))

; find all entities with a specific attribute
(->> (datoms db :aevt attr) (map :e))

; find “singleton” entity by its attr
(->> (datoms db :aevt attr) first :e)

; find N entities with lowest attr value (e.g. 10 earliest posts)
(->> (datoms db :avet attr) (take N))

; find N entities with highest attr value (e.g. 10 latest posts)
(->> (datoms db :avet attr) (reverse) (take N))

Gotchas:

  • Index lookup is usually more efficient than doing a query with a single clause.
  • Resulting iterator is calculated in constant time and small constant memory overhead.
  • Iterator supports efficient first, next, reverse, seq and is itself a sequence.
  • Will not return datoms that are not part of the index (e.g. attributes with no :db/index in schema when querying :avet index).
    • :eavt and :aevt contain all datoms.
    • :avet only contains datoms for references, :db/unique and :db/index attributes.
Index lookup. Returns a sequence of datoms (lazy iterator over actual DB index) which components (e, a, v) match passed arguments.

Datoms are sorted in index sort order. Possible `index` values are: `:eavt`, `:aevt`, `:avet`.

Usage:

    ; find all datoms for entity id == 1 (any attrs and values)
    ; sort by attribute, then value
    (datoms db :eavt 1)
    ; => (#datascript/Datom [1 :friends 2]
    ;     #datascript/Datom [1 :likes "fries"]
    ;     #datascript/Datom [1 :likes "pizza"]
    ;     #datascript/Datom [1 :name "Ivan"])

    ; find all datoms for entity id == 1 and attribute == :likes (any values)
    ; sorted by value
    (datoms db :eavt 1 :likes)
    ; => (#datascript/Datom [1 :likes "fries"]
    ;     #datascript/Datom [1 :likes "pizza"])
    
    ; find all datoms for entity id == 1, attribute == :likes and value == "pizza"
    (datoms db :eavt 1 :likes "pizza")
    ; => (#datascript/Datom [1 :likes "pizza"])

    ; find all datoms for attribute == :likes (any entity ids and values)
    ; sorted by entity id, then value
    (datoms db :aevt :likes)
    ; => (#datascript/Datom [1 :likes "fries"]
    ;     #datascript/Datom [1 :likes "pizza"]
    ;     #datascript/Datom [2 :likes "candy"]
    ;     #datascript/Datom [2 :likes "pie"]
    ;     #datascript/Datom [2 :likes "pizza"])

    ; find all datoms that have attribute == `:likes` and value == `"pizza"` (any entity id)
    ; `:likes` must be a unique attr, reference or marked as `:db/index true`
    (datoms db :avet :likes "pizza")
    ; => (#datascript/Datom [1 :likes "pizza"]
    ;     #datascript/Datom [2 :likes "pizza"])

    ; find all datoms sorted by entity id, then attribute, then value
    (datoms db :eavt) ; => (...)

Useful patterns:

    ; get all values of :db.cardinality/many attribute
    (->> (datoms db :eavt eid attr) (map :v))

    ; lookup entity ids by attribute value
    (->> (datoms db :avet attr value) (map :e))

    ; find all entities with a specific attribute
    (->> (datoms db :aevt attr) (map :e))

    ; find “singleton” entity by its attr
    (->> (datoms db :aevt attr) first :e)

    ; find N entities with lowest attr value (e.g. 10 earliest posts)
    (->> (datoms db :avet attr) (take N))

    ; find N entities with highest attr value (e.g. 10 latest posts)
    (->> (datoms db :avet attr) (reverse) (take N))

Gotchas:

- Index lookup is usually more efficient than doing a query with a single clause.
- Resulting iterator is calculated in constant time and small constant memory overhead.
- Iterator supports efficient `first`, `next`, `reverse`, `seq` and is itself a sequence.
- Will not return datoms that are not part of the index (e.g. attributes with no `:db/index` in schema when querying `:avet` index).
  - `:eavt` and `:aevt` contain all datoms.
  - `:avet` only contains datoms for references, `:db/unique` and `:db/index` attributes.
sourceraw docstring

dbclj/s

(db conn)

Returns the underlying immutable database value from a connection.

Exists for Datomic API compatibility. Prefer using @conn directly if possible.

Returns the underlying immutable database value from a connection.

Exists for Datomic API compatibility. Prefer using `@conn` directly if possible.
sourceraw docstring

db-withclj/s

(db-with db tx-data)

Applies transaction to an immutable db value, returning new immutable db value. Same as (:db-after (with db tx-data)).

Applies transaction to an immutable db value, returning new immutable db value. Same as `(:db-after (with db tx-data))`.
sourceraw docstring

db?clj/s

(db? x)

Returns true if the given value is an immutable database, false otherwise.

Returns `true` if the given value is an immutable database, `false` otherwise.
sourceraw docstring

empty-dbclj/s

(empty-db)
(empty-db schema)

Creates an empty database with an optional schema.

Usage:

(empty-db) ; => #datascript/DB {:schema {}, :datoms []}

(empty-db {:likes {:db/cardinality :db.cardinality/many}})
; => #datascript/DB {:schema {:likes {:db/cardinality :db.cardinality/many}}
;                    :datoms []}
Creates an empty database with an optional schema.

Usage:

```
(empty-db) ; => #datascript/DB {:schema {}, :datoms []}

(empty-db {:likes {:db/cardinality :db.cardinality/many}})
; => #datascript/DB {:schema {:likes {:db/cardinality :db.cardinality/many}}
;                    :datoms []}
```
sourceraw docstring

entidclj/s

(entid db eid)

Given lookup ref [unique-attr value], returns numberic entity id.

If entity does not exist, returns nil.

For numeric eid returns eid itself (does not check for entity existence in that case).

Given lookup ref `[unique-attr value]`, returns numberic entity id.

If entity does not exist, returns `nil`.

For numeric `eid` returns `eid` itself (does not check for entity existence in that case).
sourceraw docstring

entityclj/s

(entity db eid)

Retrieves an entity by its id from database. Entities are lazy map-like structures to navigate DataScript database content.

For eid pass entity id or lookup attr:

(entity db 1)
(entity db [:unique-attr :value])

If entity does not exist, nil is returned:

(entity db 100500) ; => nil

Creating an entity by id is very cheap, almost no-op, as attr access is on-demand:

(entity db 1) ; => {:db/id 1}

Entity attributes can be lazily accessed through key lookups:

(:attr (entity db 1)) ; => :value
(get (entity db 1) :attr) ; => :value

Cardinality many attributes are returned sequences:

(:attrs (entity db 1)) ; => [:v1 :v2 :v3]

Reference attributes are returned as another entities:

(:ref (entity db 1)) ; => {:db/id 2}
(:ns/ref (entity db 1)) ; => {:db/id 2}

References can be walked backwards by prepending _ to name part of an attribute:

(:_ref (entity db 2)) ; => [{:db/id 1}]
(:ns/_ref (entity db 2)) ; => [{:db/id 1}]

Reverse reference lookup returns sequence of entities unless attribute is marked as :db/isComponent:

(:_component-ref (entity db 2)) ; => {:db/id 1}

Entity gotchas:

  • Entities print as map, but are not exactly maps (they have compatible get interface though).
  • Entities are effectively immutable “views” into a particular version of a database.
  • Entities retain reference to the whole database.
  • You can’t change database through entities, only read.
  • Creating an entity by id is very cheap, almost no-op (attributes are looked up on demand).
  • Comparing entities just compares their ids. Be careful when comparing entities taken from differenct dbs or from different versions of the same db.
  • Accessed entity attributes are cached on entity itself (except backward references).
  • When printing, only cached attributes (the ones you have accessed before) are printed. See touch.
Retrieves an entity by its id from database. Entities are lazy map-like structures to navigate DataScript database content.

For `eid` pass entity id or lookup attr:

    (entity db 1)
    (entity db [:unique-attr :value])

If entity does not exist, `nil` is returned:

    (entity db 100500) ; => nil

Creating an entity by id is very cheap, almost no-op, as attr access is on-demand:

    (entity db 1) ; => {:db/id 1}

Entity attributes can be lazily accessed through key lookups:

    (:attr (entity db 1)) ; => :value
    (get (entity db 1) :attr) ; => :value

Cardinality many attributes are returned sequences:

    (:attrs (entity db 1)) ; => [:v1 :v2 :v3]

Reference attributes are returned as another entities:

    (:ref (entity db 1)) ; => {:db/id 2}
    (:ns/ref (entity db 1)) ; => {:db/id 2}

References can be walked backwards by prepending `_` to name part of an attribute:

    (:_ref (entity db 2)) ; => [{:db/id 1}]
    (:ns/_ref (entity db 2)) ; => [{:db/id 1}]

Reverse reference lookup returns sequence of entities unless attribute is marked as `:db/isComponent`:

    (:_component-ref (entity db 2)) ; => {:db/id 1}

Entity gotchas:
  
- Entities print as map, but are not exactly maps (they have compatible get interface though).
- Entities are effectively immutable “views” into a particular version of a database.
- Entities retain reference to the whole database.
- You can’t change database through entities, only read.
- Creating an entity by id is very cheap, almost no-op (attributes are looked up on demand).
- Comparing entities just compares their ids. Be careful when comparing entities taken from differenct dbs or from different versions of the same db.
- Accessed entity attributes are cached on entity itself (except backward references).
- When printing, only cached attributes (the ones you have accessed before) are printed. See [[touch]].
sourceraw docstring

entity-dbclj/s

(entity-db entity)

Returns a db that entity was created from.

Returns a db that entity was created from.
sourceraw docstring

filterclj/s

(filter db pred)

Returns a view over database that has same interface but only includes datoms for which the (pred db datom) is true. Can be applied multiple times.

Filtered DB gotchas:

  • All operations on filtered database are proxied to original DB, then filter pred is applied.
  • Not cached. You pay filter penalty every time.
  • Supports entities, pull, queries, index access.
  • Does not support with and db-with.
Returns a view over database that has same interface but only includes datoms for which the `(pred db datom)` is true. Can be applied multiple times.

Filtered DB gotchas:

- All operations on filtered database are proxied to original DB, then filter pred is applied.
- Not cached. You pay filter penalty every time.
- Supports entities, pull, queries, index access.
- Does not support [[with]] and [[db-with]].
sourceraw docstring

from-serializableclj/s

(from-serializable serializable)
(from-serializable serializable opts)

Creates db from a data structure (not string!) produced by serializable.

Opts:

:thaw-fn Non-primitive values will be deserialized using this. Must match :freeze-fn from serializable. Optional. clojure.edn/read-string by default.

Creates db from a data structure (not string!) produced by serializable.

Opts:

`:thaw-fn` Non-primitive values will be deserialized using this.
Must match :freeze-fn from serializable. Optional. `clojure.edn/read-string`
by default.
sourceraw docstring

index-rangeclj/s

(index-range db attr start end)

Returns part of :avet index between [_ attr start] and [_ attr end] in AVET sort order.

Same properties as datoms.

attr must be a reference, unique attribute or marked as :db/index true.

Usage:

(index-range db :likes "a" "zzzzzzzzz")
; => (#datascript/Datom [2 :likes "candy"]
;     #datascript/Datom [1 :likes "fries"]
;     #datascript/Datom [2 :likes "pie"]
;     #datascript/Datom [1 :likes "pizza"]
;     #datascript/Datom [2 :likes "pizza"])
 
(index-range db :likes "egg" "pineapple")
; => (#datascript/Datom [1 :likes "fries"]
;     #datascript/Datom [2 :likes "pie"])

Useful patterns:

; find all entities with age in a specific range (inclusive)
(->> (index-range db :age 18 60) (map :e))
Returns part of `:avet` index between `[_ attr start]` and `[_ attr end]` in AVET sort order.

Same properties as [[datoms]].

`attr` must be a reference, unique attribute or marked as `:db/index true`.

Usage:

    (index-range db :likes "a" "zzzzzzzzz")
    ; => (#datascript/Datom [2 :likes "candy"]
    ;     #datascript/Datom [1 :likes "fries"]
    ;     #datascript/Datom [2 :likes "pie"]
    ;     #datascript/Datom [1 :likes "pizza"]
    ;     #datascript/Datom [2 :likes "pizza"])
     
    (index-range db :likes "egg" "pineapple")
    ; => (#datascript/Datom [1 :likes "fries"]
    ;     #datascript/Datom [2 :likes "pie"])
        
Useful patterns:
  
    ; find all entities with age in a specific range (inclusive)
    (->> (index-range db :age 18 60) (map :e))
sourceraw docstring

init-dbclj/s

(init-db datoms)
(init-db datoms schema)

Low-level fn for creating database quickly from a trusted sequence of datoms.

Does no validation on inputs, so datoms must be well-formed and match schema.

Used internally in db (de)serialization. See also datom.

Low-level fn for creating database quickly from a trusted sequence of datoms.

Does no validation on inputs, so `datoms` must be well-formed and match schema.

Used internally in db (de)serialization. See also [[datom]].
sourceraw docstring

is-filteredclj/s

(is-filtered x)

Returns true if this database was filtered using filter, false otherwise.

Returns `true` if this database was filtered using [[filter]], `false` otherwise.
sourceraw docstring

listen!clj/s

(listen! conn callback)
(listen! conn key callback)

Listen for changes on the given connection. Whenever a transaction is applied to the database via transact!, the callback is called with the transaction report. key is any opaque unique value.

Idempotent. Calling listen! with the same key twice will override old callback with the new value.

Returns the key under which this listener is registered. See also unlisten!.

Listen for changes on the given connection. Whenever a transaction is applied to the database via [[transact!]], the callback is called
with the transaction report. `key` is any opaque unique value.

Idempotent. Calling [[listen!]] with the same key twice will override old callback with the new value.

Returns the key under which this listener is registered. See also [[unlisten!]].
sourceraw docstring

pullclj/s

(pull db selector eid)

Fetches data from database using recursive declarative description. See docs.datomic.com/on-prem/pull.html.

Unlike entity, returns plain Clojure map (not lazy).

Usage:

(pull db [:db/id, :name, :likes, {:friends [:db/id :name]}] 1)
; => {:db/id   1,
;     :name    "Ivan"
;     :likes   [:pizza]
;     :friends [{:db/id 2, :name "Oleg"}]}
Fetches data from database using recursive declarative description. See [docs.datomic.com/on-prem/pull.html](https://docs.datomic.com/on-prem/pull.html).

Unlike [[entity]], returns plain Clojure map (not lazy).

Usage:

    (pull db [:db/id, :name, :likes, {:friends [:db/id :name]}] 1)
    ; => {:db/id   1,
    ;     :name    "Ivan"
    ;     :likes   [:pizza]
    ;     :friends [{:db/id 2, :name "Oleg"}]}
sourceraw docstring

pull-manyclj/s

(pull-many db selector eids)

Same as pull, but accepts sequence of ids and returns sequence of maps.

Usage:

(pull-many db [:db/id :name] [1 2])
; => [{:db/id 1, :name "Ivan"}
;     {:db/id 2, :name "Oleg"}]
Same as [[pull]], but accepts sequence of ids and returns sequence of maps.

Usage:

```
(pull-many db [:db/id :name] [1 2])
; => [{:db/id 1, :name "Ivan"}
;     {:db/id 2, :name "Oleg"}]
```
sourceraw docstring

qclj/s

(q query & inputs)

Executes a datalog query. See docs.datomic.com/on-prem/query.html.

Usage:

(q '[:find ?value
     :where [_ :likes ?value]]
   db)
; => #{["fries"] ["candy"] ["pie"] ["pizza"]}
Executes a datalog query. See [docs.datomic.com/on-prem/query.html](https://docs.datomic.com/on-prem/query.html).

Usage:

```
(q '[:find ?value
     :where [_ :likes ?value]]
   db)
; => #{["fries"] ["candy"] ["pie"] ["pizza"]}
```
sourceraw docstring

reset-conn!clj/s

(reset-conn! conn db)
(reset-conn! conn db tx-meta)

Forces underlying conn value to become db. Will generate a tx-report that will remove everything from old value and insert everything from the new one.

Forces underlying `conn` value to become `db`. Will generate a tx-report that will remove everything from old value and insert everything from the new one.
sourceraw docstring

resolve-tempidclj/s

(resolve-tempid _db tempids tempid)

Does a lookup in tempids map, returning an entity id that tempid was resolved to.

Exists for Datomic API compatibility. Prefer using map lookup directly if possible.

Does a lookup in tempids map, returning an entity id that tempid was resolved to.

Exists for Datomic API compatibility. Prefer using map lookup directly if possible.
sourceraw docstring

rseek-datomsclj/s

(rseek-datoms db index)
(rseek-datoms db index c1)
(rseek-datoms db index c1 c2)
(rseek-datoms db index c1 c2 c3)
(rseek-datoms db index c1 c2 c3 c4)

Same as seek-datoms, but goes backwards until the beginning of the index.

Same as [[seek-datoms]], but goes backwards until the beginning of the index.
sourceraw docstring

schemaclj/s

(schema db)

Returns a schema of a database.

Returns a schema of a database.
sourceraw docstring

seek-datomsclj/s

(seek-datoms db index)
(seek-datoms db index c1)
(seek-datoms db index c1 c2)
(seek-datoms db index c1 c2 c3)
(seek-datoms db index c1 c2 c3 c4)

Similar to datoms, but will return datoms starting from specified components and including rest of the database until the end of the index.

If no datom matches passed arguments exactly, iterator will start from first datom that could be considered “greater” in index order.

Usage:

(seek-datoms db :eavt 1)
; => (#datascript/Datom [1 :friends 2]
;     #datascript/Datom [1 :likes "fries"]
;     #datascript/Datom [1 :likes "pizza"]
;     #datascript/Datom [1 :name "Ivan"]
;     #datascript/Datom [2 :likes "candy"]
;     #datascript/Datom [2 :likes "pie"]
;     #datascript/Datom [2 :likes "pizza"])

(seek-datoms db :eavt 1 :name)
; => (#datascript/Datom [1 :name "Ivan"]
;     #datascript/Datom [2 :likes "candy"]
;     #datascript/Datom [2 :likes "pie"]
;     #datascript/Datom [2 :likes "pizza"])

(seek-datoms db :eavt 2) 
; => (#datascript/Datom [2 :likes "candy"]
;     #datascript/Datom [2 :likes "pie"]
;     #datascript/Datom [2 :likes "pizza"])

; no datom [2 :likes "fish"], so starts with one immediately following such in index
(seek-datoms db :eavt 2 :likes "fish")
; => (#datascript/Datom [2 :likes "pie"]
;     #datascript/Datom [2 :likes "pizza"])
Similar to [[datoms]], but will return datoms starting from specified components and including rest of the database until the end of the index.

If no datom matches passed arguments exactly, iterator will start from first datom that could be considered “greater” in index order.

Usage:

    (seek-datoms db :eavt 1)
    ; => (#datascript/Datom [1 :friends 2]
    ;     #datascript/Datom [1 :likes "fries"]
    ;     #datascript/Datom [1 :likes "pizza"]
    ;     #datascript/Datom [1 :name "Ivan"]
    ;     #datascript/Datom [2 :likes "candy"]
    ;     #datascript/Datom [2 :likes "pie"]
    ;     #datascript/Datom [2 :likes "pizza"])

    (seek-datoms db :eavt 1 :name)
    ; => (#datascript/Datom [1 :name "Ivan"]
    ;     #datascript/Datom [2 :likes "candy"]
    ;     #datascript/Datom [2 :likes "pie"]
    ;     #datascript/Datom [2 :likes "pizza"])

    (seek-datoms db :eavt 2) 
    ; => (#datascript/Datom [2 :likes "candy"]
    ;     #datascript/Datom [2 :likes "pie"]
    ;     #datascript/Datom [2 :likes "pizza"])

    ; no datom [2 :likes "fish"], so starts with one immediately following such in index
    (seek-datoms db :eavt 2 :likes "fish")
    ; => (#datascript/Datom [2 :likes "pie"]
    ;     #datascript/Datom [2 :likes "pizza"])
sourceraw docstring

serializableclj/s

(serializable db)
(serializable db opts)

Converts db into a data structure (not string!) that can be fed to serializer of your choice (e.g. js/JSON.stringify in CLJS, cheshire.core/generate-string or jsonista.core/write-value-as-string in CLJ).

On JVM, serializable holds a global lock that prevents any two serializations to run in parallel (an implementation constraint, be aware).

Options:

:freeze-fn Non-primitive values will be serialized using this. Optional. pr-str by default.

Converts db into a data structure (not string!) that can be fed to serializer
of your choice (e.g. `js/JSON.stringify` in CLJS, `cheshire.core/generate-string`
or `jsonista.core/write-value-as-string` in CLJ).

On JVM, `serializable` holds a global lock that prevents any two serializations
to run in parallel (an implementation constraint, be aware).

Options:

`:freeze-fn` Non-primitive values will be serialized using this. Optional.
`pr-str` by default.
sourceraw docstring

squuidclj/s

(squuid)
(squuid msec)

Generates a UUID that grow with time. Such UUIDs will always go to the end of the index and that will minimize insertions in the middle.

Consist of 64 bits of current UNIX timestamp (in seconds) and 64 random bits (2^64 different unique values per second).

Generates a UUID that grow with time. Such UUIDs will always go to the end  of the index and that will minimize insertions in the middle.

Consist of 64 bits of current UNIX timestamp (in seconds) and 64 random bits (2^64 different unique values per second).
sourceraw docstring

squuid-time-millisclj/s

(squuid-time-millis uuid)

Returns time that was used in squuid call, in milliseconds, rounded to the closest second.

Returns time that was used in [[squuid]] call, in milliseconds, rounded to the closest second.
sourceraw docstring

tempidclj/s

(tempid part)
(tempid part x)

Allocates and returns an unique temporary id (a negative integer). Ignores part. Returns x if it is specified.

Exists for Datomic API compatibility. Prefer using negative integers directly if possible.

Allocates and returns an unique temporary id (a negative integer). Ignores `part`. Returns `x` if it is specified.

Exists for Datomic API compatibility. Prefer using negative integers directly if possible.
sourceraw docstring

touchclj/s

(touch e)

Forces all entity attributes to be eagerly fetched and cached. Only usable for debug output.

Usage:

(entity db 1) ; => {:db/id 1}
(touch (entity db 1)) ; => {:db/id 1, :dislikes [:pie], :likes [:pizza]}
Forces all entity attributes to be eagerly fetched and cached. Only usable for debug output.

Usage:

```
(entity db 1) ; => {:db/id 1}
(touch (entity db 1)) ; => {:db/id 1, :dislikes [:pie], :likes [:pizza]}
```
sourceraw docstring

transactclj/s

(transact conn tx-data)
(transact conn tx-data tx-meta)

Same as transact!, but returns an immediately realized future.

Exists for Datomic API compatibility. Prefer using transact! if possible.

Same as [[transact!]], but returns an immediately realized future.

Exists for Datomic API compatibility. Prefer using [[transact!]] if possible.
sourceraw docstring

transact!clj/s

(transact! conn tx-data)
(transact! conn tx-data tx-meta)

Applies transaction the underlying database value and atomically updates connection reference to point to the result of that transaction, new db value.

Returns transaction report, a map:

 { :db-before ...       ; db value before transaction
   :db-after  ...       ; db value after transaction
   :tx-data   [...]     ; plain datoms that were added/retracted from db-before
   :tempids   {...}     ; map of tempid from tx-data => assigned entid in db-after
   :tx-meta   tx-meta } ; the exact value you passed as `tx-meta`

Note! conn will be updated in-place and is not returned from transact!.

Usage:

; add a single datom to an existing entity (1)
(transact! conn [[:db/add 1 :name "Ivan"]])

; retract a single datom
(transact! conn [[:db/retract 1 :name "Ivan"]])

; retract single entity attribute
(transact! conn [[:db.fn/retractAttribute 1 :name]])

; ... or equivalently (since Datomic changed its API to support this):
(transact! conn [[:db/retract 1 :name]])

; retract all entity attributes (effectively deletes entity)
(transact! conn [[:db.fn/retractEntity 1]])

; create a new entity (`-1`, as any other negative value, is a tempid
; that will be replaced with DataScript to a next unused eid)
(transact! conn [[:db/add -1 :name "Ivan"]])

; check assigned id (here `*1` is a result returned from previous `transact!` call)
(def report *1)
(:tempids report) ; => {-1 296}

; check actual datoms inserted
(:tx-data report) ; => [#datascript/Datom [296 :name "Ivan"]]

; tempid can also be a string
(transact! conn [[:db/add "ivan" :name "Ivan"]])
(:tempids *1) ; => {"ivan" 297}

; reference another entity (must exist)
(transact! conn [[:db/add -1 :friend 296]])

; create an entity and set multiple attributes (in a single transaction
; equal tempids will be replaced with the same yet unused entid)
(transact! conn [[:db/add -1 :name "Ivan"]
                 [:db/add -1 :likes "fries"]
                 [:db/add -1 :likes "pizza"]
                 [:db/add -1 :friend 296]])

; create an entity and set multiple attributes (alternative map form)
(transact! conn [{:db/id  -1
                  :name   "Ivan"
                  :likes  ["fries" "pizza"]
                  :friend 296}])

; update an entity (alternative map form). Can’t retract attributes in
; map form. For cardinality many attrs, value (fish in this example)
; will be added to the list of existing values
(transact! conn [{:db/id  296
                  :name   "Oleg"
                  :likes  ["fish"]}])

; ref attributes can be specified as nested map, that will create nested entity as well
(transact! conn [{:db/id  -1
                  :name   "Oleg"
                  :friend {:db/id -2
                           :name "Sergey"}}])
                           
; reverse attribute name can be used if you want created entity to become
; a value in another entity reference
(transact! conn [{:db/id  -1
                  :name   "Oleg"
                  :_friend 296}])
; equivalent to
(transact! conn [{:db/id  -1, :name   "Oleg"}
                 {:db/id 296, :friend -1}])
; equivalent to
(transact! conn [[:db/add  -1 :name   "Oleg"]
                 [:db/add 296 :friend -1]])
Applies transaction the underlying database value and atomically updates connection reference to point to the result of that transaction, new db value.

 Returns transaction report, a map:

     { :db-before ...       ; db value before transaction
       :db-after  ...       ; db value after transaction
       :tx-data   [...]     ; plain datoms that were added/retracted from db-before
       :tempids   {...}     ; map of tempid from tx-data => assigned entid in db-after
       :tx-meta   tx-meta } ; the exact value you passed as `tx-meta`

Note! `conn` will be updated in-place and is not returned from [[transact!]].

Usage:

    ; add a single datom to an existing entity (1)
    (transact! conn [[:db/add 1 :name "Ivan"]])

    ; retract a single datom
    (transact! conn [[:db/retract 1 :name "Ivan"]])

    ; retract single entity attribute
    (transact! conn [[:db.fn/retractAttribute 1 :name]])

    ; ... or equivalently (since Datomic changed its API to support this):
    (transact! conn [[:db/retract 1 :name]])
    
    ; retract all entity attributes (effectively deletes entity)
    (transact! conn [[:db.fn/retractEntity 1]])

    ; create a new entity (`-1`, as any other negative value, is a tempid
    ; that will be replaced with DataScript to a next unused eid)
    (transact! conn [[:db/add -1 :name "Ivan"]])

    ; check assigned id (here `*1` is a result returned from previous `transact!` call)
    (def report *1)
    (:tempids report) ; => {-1 296}

    ; check actual datoms inserted
    (:tx-data report) ; => [#datascript/Datom [296 :name "Ivan"]]

    ; tempid can also be a string
    (transact! conn [[:db/add "ivan" :name "Ivan"]])
    (:tempids *1) ; => {"ivan" 297}

    ; reference another entity (must exist)
    (transact! conn [[:db/add -1 :friend 296]])

    ; create an entity and set multiple attributes (in a single transaction
    ; equal tempids will be replaced with the same yet unused entid)
    (transact! conn [[:db/add -1 :name "Ivan"]
                     [:db/add -1 :likes "fries"]
                     [:db/add -1 :likes "pizza"]
                     [:db/add -1 :friend 296]])

    ; create an entity and set multiple attributes (alternative map form)
    (transact! conn [{:db/id  -1
                      :name   "Ivan"
                      :likes  ["fries" "pizza"]
                      :friend 296}])
    
    ; update an entity (alternative map form). Can’t retract attributes in
    ; map form. For cardinality many attrs, value (fish in this example)
    ; will be added to the list of existing values
    (transact! conn [{:db/id  296
                      :name   "Oleg"
                      :likes  ["fish"]}])

    ; ref attributes can be specified as nested map, that will create nested entity as well
    (transact! conn [{:db/id  -1
                      :name   "Oleg"
                      :friend {:db/id -2
                               :name "Sergey"}}])
                               
    ; reverse attribute name can be used if you want created entity to become
    ; a value in another entity reference
    (transact! conn [{:db/id  -1
                      :name   "Oleg"
                      :_friend 296}])
    ; equivalent to
    (transact! conn [{:db/id  -1, :name   "Oleg"}
                     {:db/id 296, :friend -1}])
    ; equivalent to
    (transact! conn [[:db/add  -1 :name   "Oleg"]
                     [:db/add 296 :friend -1]])
sourceraw docstring

transact-asyncclj/s

(transact-async conn tx-data)
(transact-async conn tx-data tx-meta)

In CLJ, calls transact! on a future thread pool, returning immediately.

In CLJS, just calls transact! and returns a realized future.

In CLJ, calls [[transact!]] on a future thread pool, returning immediately.

In CLJS, just calls [[transact!]] and returns a realized future.
sourceraw docstring

unlisten!clj/s

(unlisten! conn key)

Removes registered listener from connection. See also listen!.

Removes registered listener from connection. See also [[listen!]].
sourceraw docstring

withclj/s

(with db tx-data)
(with db tx-data tx-meta)

Same as transact!, but applies to an immutable database value. Returns transaction report (see transact!).

Same as [[transact!]], but applies to an immutable database value. Returns transaction report (see [[transact!]]).
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close