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.
    input Input molecules awaiting input.
    macros Internal macros generating molecule code from custom DSL molecule constructs.
    generic Interfaces to generic information about datoms and Datomic database.
    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
    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.

  • Datom
  • Datom_0
  • Datom_1
  • Datom_10
  • Datom_11
  • Datom_12
  • Datom_13
  • Datom_14
  • Datom_15
  • Datom_16
  • Datom_17
  • Datom_18
  • Datom_19
  • Datom_2
  • Datom_20
  • Datom_21
  • Datom_22
  • Datom_3
  • Datom_4
  • Datom_5
  • Datom_6
  • Datom_7
  • Datom_8
  • Datom_9
  • 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").attr.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.

package datom

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)
Source
package.scala
See also

Tests for more generic attribute query examples.

Linear Supertypes
AnyRef, Any
Content Hierarchy

Type Members

  1. trait Datom extends AnyRef

    Base trait with generic attribute trait types shared by all arity interfaces

  2. trait Datom_0[Ns0, Ns1[_], In0[_], In1[_, _]] extends Datom

    Generic attribute interface to add first generic attribute

  3. trait Datom_1[Ns1[_], Ns2[_, _], In1[_, _], In2[_, _, _], A] extends Datom

    Generic attribute interface to add second generic attribute

  4. trait Datom_10[Ns10[_, _, _, _, _, _, _, _, _, _], Ns11[_, _, _, _, _, _, _, _, _, _, _], In10[_, _, _, _, _, _, _, _, _, _, _], In11[_, _, _, _, _, _, _, _, _, _, _, _], A, B, C, D, E, F, G, H, I, J] extends Datom
  5. trait Datom_11[Ns11[_, _, _, _, _, _, _, _, _, _, _], Ns12[_, _, _, _, _, _, _, _, _, _, _, _], In11[_, _, _, _, _, _, _, _, _, _, _, _], In12[_, _, _, _, _, _, _, _, _, _, _, _, _], A, B, C, D, E, F, G, H, I, J, K] extends Datom
  6. trait Datom_12[Ns12[_, _, _, _, _, _, _, _, _, _, _, _], Ns13[_, _, _, _, _, _, _, _, _, _, _, _, _], In12[_, _, _, _, _, _, _, _, _, _, _, _, _], In13[_, _, _, _, _, _, _, _, _, _, _, _, _, _], A, B, C, D, E, F, G, H, I, J, K, L] extends Datom
  7. trait Datom_13[Ns13[_, _, _, _, _, _, _, _, _, _, _, _, _], Ns14[_, _, _, _, _, _, _, _, _, _, _, _, _, _], In13[_, _, _, _, _, _, _, _, _, _, _, _, _, _], In14[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _], A, B, C, D, E, F, G, H, I, J, K, L, M] extends Datom
  8. trait Datom_14[Ns14[_, _, _, _, _, _, _, _, _, _, _, _, _, _], Ns15[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _], In14[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _], In15[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], A, B, C, D, E, F, G, H, I, J, K, L, M, N] extends Datom
  9. trait Datom_15[Ns15[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _], Ns16[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], In15[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], In16[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], A, B, C, D, E, F, G, H, I, J, K, L, M, N, O] extends Datom
  10. trait Datom_16[Ns16[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], Ns17[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], In16[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], In17[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P] extends Datom
  11. trait Datom_17[Ns17[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], Ns18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], In17[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], In18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q] extends Datom
  12. trait Datom_18[Ns18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], Ns19[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], In18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], In19[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R] extends Datom
  13. trait Datom_19[Ns19[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], Ns20[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], In19[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], In20[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S] extends Datom
  14. trait Datom_2[Ns2[_, _], Ns3[_, _, _], In2[_, _, _], In3[_, _, _, _], A, B] extends Datom
  15. trait Datom_20[Ns20[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], Ns21[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], In20[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], In21[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T] extends Datom
  16. trait Datom_21[Ns21[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], Ns22[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], In21[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], In22[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U] extends Datom
  17. trait Datom_22[Ns22[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], P23[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], In22[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], P24[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V] extends Datom
  18. trait Datom_3[Ns3[_, _, _], Ns4[_, _, _, _], In3[_, _, _, _], In4[_, _, _, _, _], A, B, C] extends Datom
  19. trait Datom_4[Ns4[_, _, _, _], Ns5[_, _, _, _, _], In4[_, _, _, _, _], In5[_, _, _, _, _, _], A, B, C, D] extends Datom
  20. trait Datom_5[Ns5[_, _, _, _, _], Ns6[_, _, _, _, _, _], In5[_, _, _, _, _, _], In6[_, _, _, _, _, _, _], A, B, C, D, E] extends Datom
  21. trait Datom_6[Ns6[_, _, _, _, _, _], Ns7[_, _, _, _, _, _, _], In6[_, _, _, _, _, _, _], In7[_, _, _, _, _, _, _, _], A, B, C, D, E, F] extends Datom
  22. trait Datom_7[Ns7[_, _, _, _, _, _, _], Ns8[_, _, _, _, _, _, _, _], In7[_, _, _, _, _, _, _, _], In8[_, _, _, _, _, _, _, _, _], A, B, C, D, E, F, G] extends Datom
  23. trait Datom_8[Ns8[_, _, _, _, _, _, _, _], Ns9[_, _, _, _, _, _, _, _, _], In8[_, _, _, _, _, _, _, _, _], In9[_, _, _, _, _, _, _, _, _, _], A, B, C, D, E, F, G, H] extends Datom
  24. trait Datom_9[Ns9[_, _, _, _, _, _, _, _, _], Ns10[_, _, _, _, _, _, _, _, _, _], In9[_, _, _, _, _, _, _, _, _, _], In10[_, _, _, _, _, _, _, _, _, _, _], A, B, C, D, E, F, G, H, I] extends Datom

Inherited from AnyRef

Inherited from Any

Ungrouped