Packages

  • package root

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

    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.

    Definition Classes
    root
  • package core
    Definition Classes
    molecule
  • package api
    Definition Classes
    core
  • package ast

    Internal Molecule ASTs.

    Internal Molecule ASTs.

    Definition Classes
    core
  • package composition

    Methods to build transaction, composite and nested molecules.

    Methods to build transaction, composite and nested molecules.

    Definition Classes
    core
  • package data

    Data model DSL and API.

    Data model DSL and API.

    Definition Classes
    core
  • package dsl

    Internal interfaces for auto-generated DSL boilerplate code.

    Internal interfaces for auto-generated DSL boilerplate code.

    Interfaces to the generated schema-defined DSL boilerplate code that the sbt-plugin generates when doing a sbt-compile. Molecule macros can then type-safely deduct the type structure of composed molecules.

    Definition Classes
    core
  • package exceptions

    Exceptions thrown by Molecule.

    Exceptions thrown by Molecule.

    Definition Classes
    core
  • package expression

    Attribute expressions and operations.

    Attribute expressions and operations.

    Refine attribute matches with various attribute expressions:

    Person.age(42)                           // equality
    Person.name.contains("John")             // fulltext search
    Person.age.!=(42)                        // negation (or `not`)
    Person.age.<(42)                         // comparison (< > <= >=)
    Person.name("John" or "Jonas")           // OR-logic
    Person.age()                             // apply empty value to retract value(s) in updates
    Person.hobbies.assert("golf")            // add value(s) to card-many attributes
    Person.hobbies.retract("golf")           // retract value(s) of card-many attributes
    Person.hobbies.replace("golf", "diving") // replace value(s) of card-many attributes
    Person.tags.k("en")                      // match values of map attributes by key
    Person.age(Nil)                          // match non-asserted datoms (null)
    Person.name(?)                           // initiate input molecules awaiting input at runtime
    Person.name(unify)                       // Unify attributes in self-joins

    Apply aggregate keywords to aggregate attribute value(s):

    // Aggregates on any attribute type
    Person.age(count).get.map(_.head ==> 3)         // count of asserted `age` attribute values
    Person.age(countDistinct).get.map(_.head ==> 3) // count of asserted distinct `age` attribute values
    Person.age(max).get.map(_.head ==> 38)          // maximum `age` value (using `compare`)
    Person.age(min).get.map(_.head ==> 5)           // maximum `age` value (using `compare`)
    Person.age(rand).get.map(_.head ==> 25)         // single random `age` value
    Person.age(sample).get.map(_.head ==> 27)       // single sample `age` value (when single value, same as random)
    
    // Aggregates on any attribute type, returning multiple values
    Person.age(distinct).get.map(_.head ==> Vector(5, 7, 38)) // distinct `age` values
    Person.age(max(2)).get.map(_.head ==> Vector(38, 7))      // 2 maximum `age` values
    Person.age(min(2)).get.map(_.head ==> Vector(5, 7))       // 2 minimum `age` values
    Person.age(rand(2)).get.map(_.head ==> Stream(5, ?))      // 2 random `age` values (values can re-occur)
    Person.age(sample(2)).get.map(_.head ==> Vector(7, 38))   // 2 sample `age` values
    
    // Aggregates on number attributes
    Person.age(sum).get.map(_.head ==> 50)                  // sum of all `age` numbers
    Person.age(avg).get.map(_.head ==> 16.66666667)         // average of all `age` numbers
    Person.age(median).get.map(_.head ==> 7)                // median of all `age` numbers
    Person.age(stddev).get.map(_.head ==> 15.107025591499)  // standard deviation of all `age` numbers
    Person.age(variance).get.map(_.head ==> 228.2222222222) // variance of all `age` numbers
    Definition Classes
    core
  • package factory

    Factory methods m to instantiate molecules from custom DSL molecule constructs.

    Factory methods m to instantiate molecules from custom DSL molecule constructs.

    Definition Classes
    core
  • package generic
    Definition Classes
    core
  • package AEVT
  • package AVET
  • package Datom
  • package EAVT
  • package Log
  • package Schema
  • package VAET
  • GenericAEVT
  • GenericAVET
  • GenericEAVT
  • GenericLog
  • GenericSchema
  • GenericVAET
  • package macros
    Definition Classes
    core
  • package marshalling
    Definition Classes
    core
  • package ops
    Definition Classes
    core
  • package transform
    Definition Classes
    core
  • package util

    Internal database functions for Datomic.

    Internal database functions for Datomic.

    Definition Classes
    core
p

molecule.core

generic

package generic

Type Members

  1. trait GenericAEVT extends AnyRef

    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:

    for {
      // Create AEVT Index molecule with 1 entity id argument
      _ <- AEVT(":Person/name").e.v.t.get.map(_ ==> List(
        (e1, "Ben", t2),
        (e2, "Liz", t5)
      ))
    
      // Narrow search with multiple arguments
      _ <- AEVT(":Person/name", e1).e.v.get.map(_ ==> List( (e1, "Ben") ))
      _ <- AEVT(":Person/name", e1, "Ben").e.v.get.map(_ ==> List( (e1, "Ben") ))
      _ <- AEVT(":Person/name", e1, "Ben", t2).e.v.get.map(_ ==> List( (e1, "Ben") ))
    } yield ()

    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)

  2. trait GenericAVET extends AnyRef

    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:

    for {
      // Create AVET Index molecule with 1 entity id argument
      _ <- AVET(":Person/age").e.v.t.get.map(_ ==> List(
        (e1, 42, t2),
        (e2, 37, t5)
        (e3, 14, t7),
      ))
    
      // Narrow search with multiple arguments
      _ <- AVET(":Person/age", 42).e.t.get.map(_ ==> List( (e1, t2) ))
      _ <- AVET(":Person/age", 42, e1).e.v.get.map(_ ==> List( (e1, t2) ))
      _ <- AVET(":Person/age", 42, e1, t2).e.v.get.map(_ ==> List( (e1, t2) ))
    } yield ()

    The AVET Index can be filtered by a range of values between from (inclusive) and until (exclusive) for an attribute:

    for {
      _ <- AVET.range(":Person/age", Some(14), Some(37)).v.e.t.get.map(_ ==> 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.map(_ ==> 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.map(_ ==> List(
        (37, e2, t5),
        (42, e1, t2)
      ))
    } yield ()

    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 and until cannot both be None since Molecule doesn't allow returning all datoms.

  3. trait GenericEAVT extends AnyRef

    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:

    for {
      // Create EAVT Index molecule with 1 entity id argument
      _ <- EAVT(e1).e.a.v.t.get.map(_ ==> 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.map(_ ==> List( (":Person/age", 42) ))
      _ <- EAVT(e1, ":Person/age", 42).a.v.get.map(_ ==> List( (":Person/age", 42) ))
      _ <- EAVT(e1, ":Person/age", 42, t1).a.v.get.map(_ ==> List( (":Person/age", 42) ))
    } yield ()

    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)

  4. trait GenericLog extends AnyRef

    Log interface.

    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:

    for {
      // Data from transaction t1 until t4 (exclusive)
      _ <- Log(Some(t1), Some(t4)).t.e.a.v.op.get.map(_ ==> 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.map(_ ==> 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.map(_ ==> 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)
      ))
    } yield ()

    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)
    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.

  5. trait GenericSchema extends AnyRef

    Container for Schema object.

    Container for Schema object.

    Some Datomic types map to two Scala types:

    Datomic/Scala types:

    • string - String
    • boolean - Boolean
    • long - Int, Long
    • float - Double
    • double - Double
    • bigint - BigInt
    • bigdec - BigDecimal
    • instant - java.util.Date
    • uuid - java.util.UUID
    • uri - java.net.URI
    • ref - Long
  6. trait GenericVAET extends AnyRef

    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:

    for {
      // Say we have 3 entities pointing to one entity:
      _ <- Release.e.name.Artists.e.name.get.map(_ ==> 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.map(_ ==> List(
        (a1, ":Release/artists", r1),
        (a1, ":Release/artists", r2),
        (a1, ":Release/artists", r3),
      ))
    
      // Narrow search with multiple arguments
      _ <- VAET(a1, ":Release/artist").e.get.map(_ ==> List(r1, r2, r3))
      _ <- VAET(a1, ":Release/artist", r2).e.get.map(_ ==> List(r2))
      _ <- VAET(a1, ":Release/artist", r2, t7).e.get.map(_ ==> List(r2))
    } yield ()

    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)

Ungrouped