tupelo.datomic

datom-map

(datom-map datom)
Inputs: [datom :- s/Any]
Returns: tdsk/DatomMap

Returns a plain Clojure map of an datom's attribute-value pairs.
A datom map is structured as:

  { :e      - entity id (eid)
    :a      - attribute eid
    :v      - value
    :tx     - transaction eid
    :added  - true/false (assertion/retraction) }

datoms

(datoms db-val index & components)
Inputs: [db-val :- datomic.db.Db index :- s/Keyword & components]
Returns: [tdsk/DatomMap]

Returns a lazy sequence of Clojure maps of an datom's attribute-value pairs.
A datom map is structured as:

  { :e      - entity id (eid)
    :a      - attribute eid
    :v      - value
    :tx     - transaction eid
    :added  - true/false (assertion/retraction) }

Like (datomic.api/datoms ...), but returns a seq of plain Clojure maps.  

eid->ident

(eid->ident db-val eid-val)
Inputs: [db-val :- datomic.db.Db eid-val :- tdsk/Eid]
Returns: s/Keyword

Returns the keyword ident value given an EID value

eids

(eids tx-result)
Inputs: [tx-result :- tdsk/TxResult]
Returns: [tdsk/Eid]

Returns a collection of the EIDs created in a transaction.

entity-map

(entity-map db-val entity-spec)
Inputs: [db-val :- datomic.db.Db entity-spec :- tdsk/EntitySpec]
Returns: tsk/KeyMap

Returns a map of an entity's attribute-value pairs. A simpler, eager version of datomic/entity.

entity-map-full

(entity-map-full db-val entity-spec)
Inputs: [db-val :- datomic.db.Db entity-spec :- tdsk/EntitySpec]
Returns: tsk/KeyMap

Returns a map of an entity's attribute-value pairs. A simpler, eager version of datomic/entity.

is-transaction?

(is-transaction? db-val entity-spec)
Inputs: [db-val :- datomic.db.Db entity-spec :- tdsk/EntitySpec]
Returns: s/Bool

Returns true if an entity is a transaction (i.e. it is in the :db.part/tx partition)

new-attribute

(new-attribute ident value-type & options)
Inputs: [ident :- s/Keyword value-type :- s/Keyword & options]
Returns: tsk/KeyMap

Returns the tx-data to create a new attribute in the DB.  Usage:

  (td/transact *conn*
    (attribute ident value-type & options))

The first 2 params are required. Other params are optional and will use normal Datomic default
values (false or nil) if omitted. An attribute is assumed to be :db.cardinality/one unless
otherwise specified.  Optional values are:

    :db.unique/value
    :db.unique/identity
    :db.cardinality/one     <- assumed by default
    :db.cardinality/many
    :db/index               <- assumed true by default
    :db/fulltext
    :db/isComponent
    :db/noHistory
    :db/doc                 <- *** currently unimplemented ***

new-entity

(new-entity attr-val-map)(new-entity -partition attr-val-map)
Inputs: ([attr-val-map :- tsk/KeyMap] [-partition :- s/Keyword attr-val-map :- tsk/KeyMap])
Returns: tsk/KeyMap

Returns the tx-data to create a new entity in the DB. Usage:

  (td/transact *conn*
    (new-entity           attr-val-map)   ; default partition -> :db.part/user
    (new-entity partition attr-val-map))  ; user-specified partition

where attr-val-map is a Clojure map containing attribute-value pairs to be added to the new
entity.

new-enum

(new-enum ident)
Inputs: [ident :- s/Keyword]
Returns: tsk/KeyMap

Returns the tx-data to create a new enumeration entity in the DB. Usage:

  (td/transact *conn*
    (new-enum ident))

where ident is the (keyword) name for the new enumeration entity.

new-partition

(new-partition ident)
Inputs: [ident :- s/Keyword]
Returns: tsk/KeyMap

Returns the tx-data to create a new partition in the DB. Usage:

(td/transact *conn*
  (partition ident)) 

partition-eids

(partition-eids db-val part-kw)
Inputs: [db-val :- datomic.db.Db part-kw :- s/Keyword]
Returns: [tdsk/Eid]

Returns a lazy sequence of all the EIDs in a partition.

partition-name

(partition-name db-val entity-spec)
Inputs: [db-val :- datomic.db.Db entity-spec :- tdsk/EntitySpec]
Returns: s/Keyword

Returns the partition name (the :db/ident value) for an Entity

query

macro

(query & args)
Returns search results as a set of tuples (i.e. a TupleSet, or #{ [s/Any] } in Prismatic Schema),
 where each tuple is unique. Usage:

  (td/query
     :let    [$        (d/db *conn*)     ; assign multiple variables just like
              ?name    "Caribbean"]    ;   in Clojure 'let' special form
     :yield  [?e ?name]
     :where  {:db/id ?eid  :person/name ?name  :location ?loc}
             {:db/id ?eid  :weapon/type :weapon/wit} )

Unlike datomic.api/q, the query form does not need to be wrapped in a map literal nor is any
quoting required. Most importantly, the :in keyword has been replaced with the :let keyword, and
the syntax has been copied from the Clojure let special form so that both the query variables (the
variables $ and ?name in this case) are more closely aligned with their actual values. Also, the
implicit DB $ must be explicitly tied to its data source in all cases (as shown above).
The `:let` and `:yield` clauses may be in any order, but the `:where` clause must come last.

query-pull

macro

(query-pull & args)
Returns a TupleList [Tuple] of query results, where items may be duplicated. Intended only for
use with the Datomic Pull API. Usage:

  (td/find-pull   :let    [$ (d/db *conn*) ]
                  :yield [ (pull ?eid [:location]) ]
                  :where  { :db/td ?eid :location ?loc } )

It is an error if the :yield clause does not contain a Datomic Pull API request.  

reserved-attrvals

A map that defines the set of permissible values for use in attribute definition.

User-defined attributes are special entities in Datomic. They are stored in the :db.part/db
partition, and are defined by special attributes that are built-in to Datomic (this is analgous to
the special forms that are built-in to Clojure). The root attributes are named by the following
keywords (all in the 'db' namespace):

  :db/id
  :db/ident
  :db/valueType
  :db/cardinality
  :db/unique
  :db/doc
  :db/index
  :db/fulltext
  :db/isComponent
  :db/noHistory

For each of these special attributes, this map defines the permissible values used for specifying
user-defined attributes. Most special attributes are defined by a set of permissible keyword
values. Permissible values for other special attributes are defined by a predicate function.  

retract-entity

(retract-entity entity-spec)
Inputs: [entity-spec :- tdsk/EntitySpec]
Returns: tsk/Pair

Returns the tx-data to retract all attribute-value pairs for an entity, as well as all references
to the entity by other entities. Usage:

  (td/transact *conn*
    (retract-entity entity-spec))

If the retracted entity refers to any other entity through an attribute with :db/isComponent=true,
the referenced entity will be recursively retracted as well.

retract-value

(retract-value entity-spec attribute value)
Inputs: [entity-spec :- tdsk/EntitySpec attribute :- s/Keyword value :- s/Any]
Returns: tsk/Quad

Returns the tx-data to retract an attribute-value pair for an entity. Only a single
 attribute-value pair can be retracted for each call to retract-value.  Usage:

  (td/transact *conn*
    (retract-value entity-spec attribute value))

 where the attribute-value pair must exist for the entity or the retraction will fail.  

t-query

(t-query)
Test the query macro, returns true on success.

transact

(transact conn & tx-specs)
Inputs: [conn & tx-specs]
Returns: s/Any

Like (datomic.api/transact ...) but does not require wrapping everything in a Clojure vector. Usage:

  (td/transact *conn*
    (td/new-entity attr-val-map)                 ; default partition -> :db.part/user
    (td/update entity-spec-1 attr-val-map-1)
    (td/update entity-spec-2 attr-val-map-2))

transactions

(transactions db-val)
Inputs: [db-val :- datomic.db.Db]
Returns: [tsk/KeyMap]

Returns a lazy sequence of entity-maps for all DB transactions

tx-datoms

(tx-datoms db-val tx-result)
Inputs: [db-val :- datomic.db.Db tx-result :- tdsk/TxResult]
Returns: s/Any

Returns a vector of datom-maps from a TxResult

txid

(txid tx-result)
Inputs: [tx-result :- tdsk/TxResult]
Returns: tdsk/Eid

Returns the EID of a transaction

update

(update entity-spec attr-val-map)
Inputs: [entity-spec :- tdsk/EntitySpec attr-val-map :- tsk/KeyMap]
Returns: tsk/KeyMap

Returns the tx-data to update an existing entity. Usage:

  (td/transact *conn*
    (update entity-spec attr-val-map))

 where attr-val-map is a Clojure map containing attribute-value pairs to be added to the new
 entity.  For attributes with :db.cardinality/one, Datomic will (automatically) retract the
 previous value prior to the insertion of the new value. For attributes with :db.cardinality/many,
 the new value will be accumulated into the current set of values.