Packages

  • package root

    Documentation/API for the Molecule library - a meta DSL for the Datomic database.

    Manual | scalamolecule.org | Github | Forum

    Definition Classes
    root
  • package molecule

    Molecule library - a Scala meta-DSL for the Datomic database.

    Molecule library - a Scala meta-DSL for the Datomic database.

    See api package for various api imports to start using Molecule.

    Sub-packages

    api Molecule API.
    ast Internal Molecule ASTs.
    boilerplate Internal interfaces for auto-generated DSL boilerplate code.
    composition    Builder methods to compose molecules.
    exceptions Exceptions thrown by Molecule.
    expression Attribute expressions and operations.
    facade Molecule facades to Datomic.
    factory Implicit macro methods `m` to instantiate molecules from custom DSL molecule constructs.
    generic Interfaces to generic information about datoms and Datomic database.
    input Input molecules awaiting input.
    macro Internal macros generating molecule code from custom DSL molecule constructs.
    ops Internal operational helpers for transforming DSL to molecule.
    schema Schema definition DSL.
    transform Internal transformers from DSL to Model/Query/Transaction.
    util Internal Java database functions for Datomic.

    Definition Classes
    root
  • package generic

    Interfaces to get generic information about data and schema.

    Interfaces to get generic information about data and schema.

    • Datom - Generic Datom attributes in molecules
    • Log - Datoms sorted by transaction/time
    • 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
    • Schema - Meta information about the current database schema.
    Definition Classes
    molecule
  • package datom

    Generic Datom attribute interfaces of all arities.

    Generic Datom attribute interfaces of all arities.

    "Generic attributes" are special pre-defined attributes that can be combined with custom attributes in molecules to return meta data:

    // Get id of Ben entity with `e`
    Person.e.name.get.head === (benEntityId, "Ben")
    
    // When was Ben's age updated? Using `txInstant`
    Person(benEntityId).age.txInstant.get.head === (42, <April 4, 2019>) // (Date)
    
    // With a history db we can access the transaction number `t` and
    // assertion/retraction statusses with `op`
    Person(benEntityId).age.t.op.getHistory === List(
      (41, t1, true),  // age 41 asserted in transaction t1
      (41, t2, false), // age 41 retracted in transaction t2
      (42, t2, true)   // age 42 asserted in transaction t2
    )

    Available generic attributes:

    • 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)
    Definition Classes
    generic
    See also

    Tests for more generic attribute query examples.

  • package index

    Datomic Index APIs in Molecule.

    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)
    )
    Definition Classes
    generic
    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.

  • package schema

    Generic Schema attribute interfaces of all arities.

    Generic Schema attribute interfaces of all arities.

    The generic Schema interface provides attributes to build molecules that query the Schema structure of the current database.

    // List of attribute entity ids
    val attrIds: Seq[Long] = Schema.id.get
    
    // Attribute name elements
    Schema.a.part.ns.nsFull.attr.get === List (
      (":sales_Customer/name", "sales", "customer", "sales_Customer", "name"),
      (":sales_Customer/name", "sales", "customer", "sales_Customer", "name"),
      // etc..
    )
    
    // Datomic type and cardinality of attributes
    Schema.a.tpe.card.get === List (
      (":sales_customer/name", "string", "one"),
      (":accounting_invoice/invoiceLine", "ref", "many"),
    )
    
    // Optional docs and attribute options
    // These can be retrieved as mandatory or optional values
    Schema.a
          .index
          .doc$
          .unique$
          .fulltext$
          .isComponent$
          .noHistory$
          .get === List(
      (":sales_customer/name",
        true,            // indexed
        "Customer name", // doc
        None,            // Uniqueness not set
        Some(true),      // Fulltext search set so that we can search for names
        None,            // Not a component
        None             // History is preserved (noHistory not set)
        ),
      (":accounting_invoice/invoiceLine",
        true,                   // indexed
        "Ref to Invoice lines", // doc
        None,                   // Uniqueness not set
        None,                   // Fulltext search not set
        Some(true),             // Invoice is a component - owns invoice lines
        None                    // History is preserved (noHistory not set)
        ),
    )
    
    // Defined enum values
    Schema.a.enum.get.groupBy(_._1).map(g => g._1 -> g._2) === Map(
      ":person/gender" -> List("female", "male"),
      ":interests/sports" -> List("golf", "basket", "badminton")
    )
    
    // Schema transaction times
    Schema.t.tx.txInstant.get === List(
      (t1, tx1, <Date: 2018-11-07 09:28:10>), // Initial schema transaction
      (t2, tx2, <Date: 2019-01-12 12:43:27>), // Additional schema attribute definitions...
    )

    Apply expressions to narrow the returned selection of Schema data:

    // Namespaces in the "gen" partition (partition name tacit)
    Schema.part_("location").ns.get === List("country", "region", etc...)
    
    // Attributes in the "Person" namespace
    Schema.ns_("person").a.get === List("name", "age", "hobbies", etc...)
    
    // How many enum attributes?
    Schema.enum_.a(count).get === List(2)
    Definition Classes
    generic
    Note

    Schema attributes defined in Datomic's bootstrap process that are not related to the current database are transparently filtered out from all Schema queries.

    See also

    Tests for more Schema query examples.

  • GenericLog
  • Log
  • Log_0
  • Log_1
  • Log_2
  • Log_3
  • Log_4
  • Log_5
  • Log_6
  • Log_7

trait Log extends GenericNs

Log interface.

Datomic's database log is a recording of all transaction data in historic order, organized for efficient access by transaction.

Instantiate Log object with tx range arguments between from (inclusive) and until (exclusive), and add Log attributes to be returned as tuples of data:

// Data from transaction t1 until t4 (exclusive)
Log(Some(t1), Some(t4)).t.e.a.v.op.get === List(
  (t1, e1, ":person/name", "Ben", true),
  (t1, e1, ":person/age", 41, true),

  (t2, e2, ":person/name", "Liz", true),
  (t2, e2, ":person/age", 37, true),

  (t3, e1, ":person/age", 41, false),
  (t3, e1, ":person/age", 42, true)
)

// If `from` is None, the range starts from the beginning
Log(None, Some(t3)).v.e.t.get === List(
  (t1, e1, ":person/name", "Ben", true),
  (t1, e1, ":person/age", 41, true),

  (t2, e2, ":person/name", "Liz", true),
  (t2, e2, ":person/age", 37, true)

  // t3 not included
)

// If `until` is None, the range goes to the end
Log(Some(t2), None).v.e.t.get === List(
  // t1 not included

  (t2, e2, ":person/name", "Liz", true),
  (t2, e2, ":person/age", 37, true),

  (t3, e1, ":person/age", 41, false),
  (t3, e1, ":person/age", 42, true)
)

Log 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)
Source
Log.scala
Note

Contrary to the Datomic Log which is map of individual transactions the Molecule Log implementation is flattened to be one continuous list of transaction data. This is to have a transparent unified return type as all other molecules returning data. Data can always be grouped if needed.

Linear Supertypes
GenericNs, AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Log
  2. GenericNs
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. final class a[Ns, In] extends OneString[Ns, In] with Indexed

    (Partition)-Namespace-prefixed attribute name (":part_Ns/attr")

  2. final class e[Ns, In] extends OneLong[Ns, In] with Indexed

    Entity id (Long)

  3. final class op[Ns, In] extends OneBoolean[Ns, In] with Indexed

    Transaction operation: assertion (true) or retraction (false)

  4. final class t[Ns, In] extends OneLong[Ns, In] with Indexed

    Transaction point in time t (Long/Int)

  5. final class tx[Ns, In] extends OneLong[Ns, In] with Indexed

    Transaction entity id (Long)

  6. final class txInstant[Ns, In] extends OneDate[Ns, In] with Indexed

    Transaction wall-clock time (Date)

  7. final class v[Ns, In] extends OneAny[Ns, In] with Indexed

    Datom value (Any)

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  10. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  11. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  12. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  13. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  14. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  15. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  16. def toString(): String
    Definition Classes
    AnyRef → Any
  17. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  18. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  19. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )

Inherited from GenericNs

Inherited from AnyRef

Inherited from Any

Ungrouped