package index
Datomic Index APIs in Molecule.
Datomic maintains four indexes that contain ordered sets of datoms.
Each of these indexes is named based on the sort order used:
- EAVT - Datoms sorted by Entity-Attribute-Value-Transaction
- AVET - Datoms sorted by Attribute-Value-Entity-Transaction
- AEVT - Datoms sorted by Attribute-Entity-Value-Transaction
- VAET - "Reverse index" for reverse lookup of ref types
Create an Index molecule by instantiating an Index object with one or more arguments in the order of the Index's elements. Datoms are returned as tuples of data depending of which generic attributes you add to the Index molecule:
// Create EAVT Index molecule with 1 entity id argument EAVT(e1).e.a.v.t.get === List( (e1, ":Person/name", "Ben", t1), (e1, ":Person/age", 42, t2), (e1, ":Golf/score", 5.7, t2) ) // Maybe we are only interested in the attribute/value pairs: EAVT(e1).a.v.get === List( (":Person/name", "Ben"), (":Person/age", 42), (":Golf/score", 5.7) ) // Two arguments to narrow the search EAVT(e1, ":Person/age").a.v.get === List( (":Person/age", 42) )
- Source
- package.scala
- Note
The Molecule Index API's don't allow returning the whole Index/the whole database. So omitting arguments constructing the Index object (like
EAVT.e.a.v.t.get
) will throw an exception.
Please use Datomics API if you need to return the whole database Index:
conn.db.datoms(datomic.Database.EAVT)
- See also
Tests for more Index query examples.
Type Members
- trait AEVT extends GenericNs
AEVT Index.
AEVT Index.
"The AEVT index provides efficient access to all values for a given attribute, comparable to traditional column access style." (from Datomic documentation)
Access the AEVT Index in Molecule by instantiating an AEVT object with one or more arguments and then add generic attributes:
// Create AEVT Index molecule with 1 entity id argument AEVT(":Person/name").e.v.t.get === List( (e1, "Ben", t2), (e2, "Liz", t5) ) // Narrow search with multiple arguments AEVT(":Person/name", e1).e.v.get === List( (e1, "Ben") ) AEVT(":Person/name", e1, "Ben").e.v.get === List( (e1, "Ben") ) AEVT(":Person/name", e1, "Ben", t2).e.v.get === List( (e1, "Ben") )
Index attributes available:
e
- Entity id (Long)a
- Full attribute name like ":Person/name" (String)v
- Value of Datoms (Any)t
- Transaction pointer (Long/Int)tx
- Transaction entity id (Long)txInstant
- Transaction wall clock time (java.util.Date)op
- Operation status: assertion (true) / retraction (false)
- Note
The Molecule Index API's don't allow returning the whole Index/the whole database. So omitting arguments constructing the Index object (like
AEVT.a.e.v.t.get
) will throw an exception.
Please use Datomics API if you need to return the whole database Index:
conn.db.datoms(datomic.Database.AEVT)
- See also
Tests for more Index query examples.
- trait AEVT_0 extends AEVT with OutIndex_0
AEVT interface to add a first generic attribute to molecule.
- trait AEVT_1[A] extends AEVT with OutIndex_1[A]
AEVT interface to add a second generic attribute to molecule.
- trait AEVT_2[A, B] extends AEVT with OutIndex_2[A, B]
- trait AEVT_3[A, B, C] extends AEVT with OutIndex_3[A, B, C]
- trait AEVT_4[A, B, C, D] extends AEVT with OutIndex_4[A, B, C, D]
- trait AEVT_5[A, B, C, D, E] extends AEVT with OutIndex_5[A, B, C, D, E]
- trait AEVT_6[A, B, C, D, E, F] extends AEVT with OutIndex_6[A, B, C, D, E, F]
- trait AEVT_7[A, B, C, D, E, F, G] extends AEVT with OutIndex_7[A, B, C, D, E, F, G]
- trait AVET extends GenericNs
AVET Index.
AVET Index.
"The AVET index provides efficient access to particular combinations of attribute and value." (from Datomic documentation)
Access the AVET Index in Molecule by instantiating an AVET object with one or more arguments and then add generic attributes:
// Create AVET Index molecule with 1 entity id argument AVET(":Person/age").e.v.t.get === List( (e1, 42, t2), (e2, 37, t5) (e3, 14, t7), ) // Narrow search with multiple arguments AVET(":Person/age", 42).e.t.get === List( (e1, t2) ) AVET(":Person/age", 42, e1).e.v.get === List( (e1, t2) ) AVET(":Person/age", 42, e1, t2).e.v.get === List( (e1, t2) )
The AVET Index can be filtered by a range of values between
from
(inclusive) anduntil
(exclusive) for an attribute:AVET.range(":Person/age", Some(14), Some(37)).v.e.t.get === List( (14, e4, t7) // 14 is included in value range // 37 not included in value range // 42 outside value range ) // If `from` is None, the range starts from the beginning AVET.range(":Person/age", None, Some(40)).v.e.t.get === List( (14, e3, t7), (37, e2, t5), ) // If `until` is None, the range goes to the end AVET.range(":Person/age", Some(20), None).v.e.t.get === List( (37, e2, t5), (42, e1, t2) )
Index attributes available:
e
- Entity id (Long)a
- Full attribute name like ":Person/name" (String)v
- Value of Datoms (Any)t
- Transaction pointer (Long/Int)tx
- Transaction entity id (Long)txInstant
- Transaction wall clock time (java.util.Date)op
- Operation status: assertion (true) / retraction (false)
- Note
The Molecule Index API's don't allow returning the whole Index/the whole database. So omitting arguments constructing the Index object (like
AVET.a.v.e.t.get
) will throw an exception.
Please use Datomics API if you need to return the whole database Index:
conn.db.datoms(datomic.Database.AVET)
from
anduntil
cannot both be None since Molecule doesn't allow returning all datoms.- See also
Tests for more Index query examples.
- trait AVET_0 extends AVET with OutIndex_0
AVET interface to add a first generic attribute to molecule.
- trait AVET_1[A] extends AVET with OutIndex_1[A]
AVET interface to add a second generic attribute to molecule.
- trait AVET_2[A, B] extends AVET with OutIndex_2[A, B]
- trait AVET_3[A, B, C] extends AVET with OutIndex_3[A, B, C]
- trait AVET_4[A, B, C, D] extends AVET with OutIndex_4[A, B, C, D]
- trait AVET_5[A, B, C, D, E] extends AVET with OutIndex_5[A, B, C, D, E]
- trait AVET_6[A, B, C, D, E, F] extends AVET with OutIndex_6[A, B, C, D, E, F]
- trait AVET_7[A, B, C, D, E, F, G] extends AVET with OutIndex_7[A, B, C, D, E, F, G]
- trait EAVT extends GenericNs
EAVT Index.
EAVT Index.
"The EAVT index provides efficient access to everything about a given entity. Conceptually this is very similar to row access style in a SQL database, except that entities can possess arbitrary attributes rather then being limited to a predefined set of columns." (from Datomic documentation)
Access the EAVT Index in Molecule by instantiating an EAVT object with one or more arguments and then add generic attributes:
// Create EAVT Index molecule with 1 entity id argument EAVT(e1).e.a.v.t.get === List( (e1, ":Person/name", "Ben", t1), (e1, ":Person/age", 42, t2), (e1, ":Golf/score", 5.7, t2) ) // Narrow search with multiple arguments EAVT(e1, ":Person/age").a.v.get === List( (":Person/age", 42) ) EAVT(e1, ":Person/age", 42).a.v.get === List( (":Person/age", 42) ) EAVT(e1, ":Person/age", 42, t1).a.v.get === List( (":Person/age", 42) )
Index attributes available:
e
- Entity id (Long)a
- Full attribute name like ":Person/name" (String)v
- Value of Datoms (Any)t
- Transaction pointer (Long/Int)tx
- Transaction entity id (Long)txInstant
- Transaction wall clock time (java.util.Date)op
- Operation status: assertion (true) / retraction (false)
- Note
The Molecule Index API's don't allow returning the whole Index/the whole database. So omitting arguments constructing the Index object (like
EAVT.e.a.v.t.get
) will throw an exception.
Please use Datomics API if you need to return the whole database Index:
conn.db.datoms(datomic.Database.EAVT)
- See also
Tests for more Index query examples.
- trait EAVT_0 extends EAVT with OutIndex_0
EAVT interface to add a first generic attribute to molecule.
- trait EAVT_1[A] extends EAVT with OutIndex_1[A]
EAVT interface to add a second generic attribute to molecule.
- trait EAVT_2[A, B] extends EAVT with OutIndex_2[A, B]
- trait EAVT_3[A, B, C] extends EAVT with OutIndex_3[A, B, C]
- trait EAVT_4[A, B, C, D] extends EAVT with OutIndex_4[A, B, C, D]
- trait EAVT_5[A, B, C, D, E] extends EAVT with OutIndex_5[A, B, C, D, E]
- trait EAVT_6[A, B, C, D, E, F] extends EAVT with OutIndex_6[A, B, C, D, E, F]
- trait EAVT_7[A, B, C, D, E, F, G] extends EAVT with OutIndex_7[A, B, C, D, E, F, G]
- trait GenericAEVT extends AnyRef
Container for AEVT Index object.
- trait GenericAVET extends AnyRef
Container for AVET Index object.
- trait GenericEAVT extends AnyRef
Container for EAVT Index object.
- trait GenericVAET extends AnyRef
Container for VAET reverse Index object.
- trait VAET extends GenericNs
VAET reverse Index.
VAET reverse Index.
"The VAET index contains all and only datoms whose attribute has a :db/valueType of :db.type/ref. This is also known as the reverse index, since it allows efficient navigation of relationships in reverse." (from Datomic documentation)
Access the VAET Index in Molecule by instantiating a VAET object with one or more arguments and then add generic attributes:
// Say we have 3 entities pointing to one entity: Release.e.name.Artists.e.name.get === List( (r1, "Abbey Road", a1, "The Beatles"), (r2, "Magical Mystery Tour", a1, "The Beatles"), (r3, "Let it be", a1, "The Beatles"), ) // .. then we can get the reverse relationships with the VAET Index: VAET(a1).v.a.e.get === List( (a1, ":Release/artists", r1), (a1, ":Release/artists", r2), (a1, ":Release/artists", r3), ) // Narrow search with multiple arguments VAET(a1, ":Release/artist").e.get === List(r1, r2, r3) VAET(a1, ":Release/artist", r2).e.get === List(r2) VAET(a1, ":Release/artist", r2, t7).e.get === List(r2)
Index attributes available:
e
- Entity id (Long)a
- Full attribute name like ":Person/name" (String)v
- Value of Datoms (Any)t
- Transaction pointer (Long/Int)tx
- Transaction entity id (Long)txInstant
- Transaction wall clock time (java.util.Date)op
- Operation status: assertion (true) / retraction (false)
- Note
The Molecule Index API's don't allow returning the whole Index/the whole database. So omitting arguments constructing the Index object (like
VAET.v.a.e.t.get
) will throw an exception.
Please use Datomics API if you need to return the whole database Index:
conn.db.datoms(datomic.Database.VAET)
- See also
Tests for more Index query examples.
- trait VAET_0 extends VAET with OutIndex_0
VAET interface to add a first generic attribute to molecule.
- trait VAET_1[A] extends VAET with OutIndex_1[A]
VAET interface to add a second generic attribute to molecule.
- trait VAET_2[A, B] extends VAET with OutIndex_2[A, B]
- trait VAET_3[A, B, C] extends VAET with OutIndex_3[A, B, C]
- trait VAET_4[A, B, C, D] extends VAET with OutIndex_4[A, B, C, D]
- trait VAET_5[A, B, C, D, E] extends VAET with OutIndex_5[A, B, C, D, E]
- trait VAET_6[A, B, C, D, E, F] extends VAET with OutIndex_6[A, B, C, D, E, F]
- trait VAET_7[A, B, C, D, E, F, G] extends VAET with OutIndex_7[A, B, C, D, E, F, G]
Documentation/API for the Molecule library - a meta DSL for the Datomic database.
Manual | scalamolecule.org | Github | Forum