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

    action Actions on molecules and entities.
    api Molecule import interfaces of various arities.
    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 input

    Input molecules awaiting input.

    Input molecules awaiting input.

    Input molecules are molecules that awaits one or more inputs at runtime. When input value is applied, the input molecule is resolved and a standard molecule is returned that we can then call actions on.

    Input molecule queries are cached by Datomic. So there is a runtime performance gain in using input molecules. Furthermore, input molecules are a good fit for re-use for queries where only a few parameters change.

    Input molecules can await 1, 2 or 3 inputs and are constructed by applying the ? marker to attributes. If one marker is applied, we get a InputMolecule_1, 2 inputs creates an InputMolecule_2 and 3 an InputMolecule_3.

    The three input molecule interfaces come in arity-versions corresponding to the number of non-?-marked attributes in the input molecule. Let's see a simple example:

    // Sample data
    Person.name.age insert List(("Ben", 42), ("Liz", 34))
    
    // Input molecule created at compile time. Awaits a name of type String
    val ageOfPersons: InputMolecule_1.InputMolecule_1_01[String, Int] = m(Person.name_(?).age)
    
    // Resolved molecule. "Ben" input is matched against name attribute
    val ageOfPersonsNamedBen: Molecule.Molecule01[Int] = ageOfPersons.apply("Ben")
    
    // Calling action on resolved molecule.
    // (Only age is returned since name was marked as tacit with the underscore notation)
    ageOfPersonsNamedBen.get === List(42)
    
    // Or we can re-use the input molecule straight away
    ageOfPersons("Liz").get === List(34)
    Definition Classes
    molecule
  • package exception
    Definition Classes
    input
  • InputMolecule
  • InputMolecule_1
  • InputMolecule_2
  • InputMolecule_3

trait InputMolecule_3[I1, I2, I3] extends InputMolecule

Shared interfaces of input molecules awaiting 3 inputs.

// Sample data set
Person.name.profession.age.score insert List(
  ("Ann", "doctor", 37, 1.0),
  ("Ben", "teacher", 37, 1.0),
  ("Joe", "teacher", 32, 1.0),
  ("Liz", "teacher", 28, 2.0)
)

// Input molecule awaiting 3 inputs for `profession`, `age` and `score`
val profAgeScore = m(Person.name.profession_(?).age_(?).score_(?))


// A. Triples of input .................................

// One triple as params
profAgeScore.apply("doctor", 37, 1.0).get === List("Ann")

// One or more triples
profAgeScore.apply(("doctor", 37, 1.0)).get === List("Ann")
profAgeScore.apply(("doctor", 37, 1.0), ("teacher", 37, 1.0)).get.sorted === List("Ann", "Ben")

// One or more logical triples
// [triple-expression] or [triple-expression] or ...
profAgeScore.apply(("doctor" and 37 and 1.0) or ("teacher" and 32 and 1.0)).get.sorted === List("Ann", "Joe")

// List of triples
profAgeScore.apply(Seq(("doctor", 37, 1.0))).get === List("Ann")
profAgeScore.apply(Seq(("doctor", 37, 1.0), ("teacher", 37, 1.0))).get.sorted === List("Ann", "Ben")


// B. 3 groups of input, one for each input attribute .................................

// Three expressions
// [profession-expression] and [age-expression] and [score-expression]
profAgeScore.apply("doctor" and 37 and 1.0).get === List("Ann")
profAgeScore.apply(("doctor" or "teacher") and 37 and 1.0).get.sorted === List("Ann", "Ben")
profAgeScore.apply(("doctor" or "teacher") and (37 or 32) and 1.0).get.sorted === List("Ann", "Ben", "Joe")
profAgeScore.apply(("doctor" or "teacher") and (37 or 32) and (1.0 or 2.0)).get.sorted === List("Ann", "Ben", "Joe")

// Three lists
profAgeScore.apply(Seq("doctor"), Seq(37), Seq(1.0)).get === List("Ann")
profAgeScore.apply(Seq("doctor", "teacher"), Seq(37), Seq(1.0)).get.sorted === List("Ann", "Ben")
I1

Type of input matching first attribute with ? marker (profession: String)

I2

Type of input matching second attribute with ? marker (age: Int)

I3

Type of input matching third attribute with ? marker (score: Double)

Source
InputMolecule_3.scala
See also

molecule.input.InputMolecule | Manual

Linear Supertypes
Ordering
  1. Grouped
  2. Alphabetic
  3. By Inheritance
Inherited
  1. InputMolecule_3
  2. InputMolecule
  3. MoleculeBase
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract val _model: Model

    Internal Model representation of molecule.

    Internal Model representation of molecule.

    Molecule transforms custom boilerplate DSL constructs to Datomic queries in 3 steps:

    Custom DSL molecule --> Model --> Query --> Datomic query string

    Definition Classes
    MoleculeBase
  2. abstract val _nestedQuery: Option[Query]

    Internal optional Query representation of nested molecule with added entity search for each level.

    Internal optional Query representation of nested molecule with added entity search for each level.

    Molecule transforms custom boilerplate DSL constructs to Datomic queries in 3 steps:

    Custom DSL molecule --> Model --> Query --> Datomic query string

    Definition Classes
    MoleculeBase
  3. abstract val _query: Query

    Internal Query representation of molecule.

    Internal Query representation of molecule.

    Molecule transforms custom boilerplate DSL constructs to Datomic queries in 3 steps:

    Custom DSL molecule --> Model --> Query --> Datomic query string

    Definition Classes
    MoleculeBase
  4. abstract def apply(in1: Seq[I1], in2: Seq[I2], in3: Seq[I3])(implicit conn: Conn): MoleculeBase

    Resolve input molecule by applying 3 groups of values, one for each of the 3 input attributes

    Resolve input molecule by applying 3 groups of values, one for each of the 3 input attributes

    // Sample data set
    Person.name.profession.age.score insert List(
      ("Ann", "doctor", 37, 1.0),
      ("Ben", "teacher", 37, 1.0),
      ("Joe", "teacher", 32, 1.0),
      ("Liz", "teacher", 28, 2.0)
    )
    
    // Input molecule awaiting 3 inputs for `profession`, `age` and `score`
    val profAgeScore = m(Person.name.profession_(?).age_(?).score_(?))
    
    // Apply 3 Seq of values, each matching one of the input attributes
    proOfAge(Seq("doctor"), Seq(37)).get === List("Ann")
    proOfAge(Seq("doctor", "teacher"), Seq(37, 32)).get.sorted === List("Ann", "Ben", "Joe")
    
    // Number of arguments in each Seq don't have to match but can be asymmetric
    profAgeScore.apply(Seq("doctor"), Seq(37), Seq(1.0)).get === List("Ann")
    profAgeScore.apply(Seq("doctor", "teacher"), Seq(37), Seq(1.0)).get.sorted === List("Ann", "Ben")
    in1

    Seq of values matching first input attribute (professions: Seq[String])

    in2

    Seq of values matching second input attribute (ages: Seq[Int])

    in3

    Seq of values matching third input attribute (scores: Seq[Double])

    conn

    Implicit Conn in scope

    returns

    Resolved molecule that can be queried

  5. abstract def apply(and: And3[I1, I2, I3])(implicit conn: Conn): MoleculeBase

    Resolve input molecule by applying 3 groups of expressions, one for each of the 3 input attributes

    Resolve input molecule by applying 3 groups of expressions, one for each of the 3 input attributes

    // Sample data set
    Person.name.profession.age.score insert List(
      ("Ann", "doctor", 37, 1.0),
      ("Ben", "teacher", 37, 1.0),
      ("Joe", "teacher", 32, 1.0),
      ("Liz", "teacher", 28, 2.0)
    )
    
    // Input molecule awaiting 3 inputs for `profession`, `age` and `score`
    val profAgeScore = m(Person.name.profession_(?).age_(?).score_(?))
    
    // Apply 3 expressions, one for each input attribute
    // [profession-expression] and [age-expression] and [score-expression]
    profAgeScore.apply("doctor" and 37 and 1.0).get === List("Ann")
    profAgeScore.apply(("doctor" or "teacher") and 37 and 1.0).get.sorted === List("Ann", "Ben")
    profAgeScore.apply(("doctor" or "teacher") and (37 or 32) and 1.0).get.sorted === List("Ann", "Ben", "Joe")
    profAgeScore.apply(("doctor" or "teacher") and (37 or 32) and (1.0 or 2.0)).get.sorted === List("Ann", "Ben", "Joe")
    and

    First input expr and second input expr and third input expr

    conn

    Implicit Conn in scope

    returns

    Resolved molecule that can be queried

  6. abstract def apply(ins: Seq[(I1, I2, I3)])(implicit conn: Conn): MoleculeBase

    Resolve input molecule by applying Seq of value triples

    Resolve input molecule by applying Seq of value triples

    // Sample data set
    Person.name.profession.age.score insert List(
      ("Ann", "doctor", 37, 1.0),
      ("Ben", "teacher", 37, 1.0),
      ("Joe", "teacher", 32, 1.0),
      ("Liz", "teacher", 28, 2.0)
    )
    
    // Input molecule awaiting 3 inputs for `profession`, `age` and `score`
    val profAgeScore = m(Person.name.profession_(?).age_(?).score_(?))
    
    // Apply Seq of one or more value triples, each matching all 3 input attributes
    profAgeScore.apply(Seq(("doctor", 37, 1.0))).get === List("Ann")
    profAgeScore.apply(Seq(("doctor", 37, 1.0), ("teacher", 37, 1.0))).get.sorted === List("Ann", "Ben")
    ins

    Seq of value triples, each matching the 3 input attributes

    conn

    Implicit Conn in scope

    returns

    Resolved molecule that can be queried

  7. abstract def apply(or: Or3[I1, I2, I3])(implicit conn: Conn): MoleculeBase

    Resolve input molecule by applying one or more triples of expressions, each matching the 3 input attributes

    Resolve input molecule by applying one or more triples of expressions, each matching the 3 input attributes

    // Sample data set
    Person.name.profession.age.score insert List(
      ("Ann", "doctor", 37, 1.0),
      ("Ben", "teacher", 37, 1.0),
      ("Joe", "teacher", 32, 1.0),
      ("Liz", "teacher", 28, 2.0)
    )
    
    // Input molecule awaiting 3 inputs for `profession`, `age` and `score`
    val profAgeScore = m(Person.name.profession_(?).age_(?).score_(?))
    
    // Apply two or more triple expressions, each matching all 3 input attributes
    // [profession/age/score-expression] or [profession/age/score-expression] or ...
    profAgeScore.apply(("doctor" and 37 and 1.0) or ("teacher" and 32 and 1.0)).get.sorted === List("Ann", "Joe")
    or

    Two or more tuple3 expressions separated by or

    conn

    Implicit Conn in scope

    returns

    Resolved molecule that can be queried

  8. abstract def apply(tpl: (I1, I2, I3), tpls: (I1, I2, I3)*)(implicit conn: Conn): MoleculeBase

    Resolve input molecule by applying one or more value triples

    Resolve input molecule by applying one or more value triples

    // Sample data set
    Person.name.profession.age.score insert List(
      ("Ann", "doctor", 37, 1.0),
      ("Ben", "teacher", 37, 1.0),
      ("Joe", "teacher", 32, 1.0),
      ("Liz", "teacher", 28, 2.0)
    )
    
    // Input molecule awaiting 3 inputs for `profession`, `age` and `score`
    val profAgeScore = m(Person.name.profession_(?).age_(?).score_(?))
    
    // Apply one or more value triples, each matching all 3 input attributes
    profAgeScore.apply(("doctor", 37, 1.0)).get === List("Ann")
    profAgeScore.apply(("doctor", 37, 1.0), ("teacher", 37, 1.0)).get.sorted === List("Ann", "Ben")
    tpl

    First triple of values matching the 3 input attributes

    tpls

    Optional more triples of values matching both input attributes

    conn

    Implicit Conn in scope

    returns

    Resolved molecule that can be queried

  9. abstract def apply(i1: I1, i2: I2, i3: I3)(implicit conn: Conn): MoleculeBase

    Resolve input molecule by applying 3 input values as individual args

    Resolve input molecule by applying 3 input values as individual args

    // Sample data set
    Person.name.profession.age.score insert List(
      ("Ann", "doctor", 37, 1.0),
      ("Ben", "teacher", 37, 1.0),
      ("Joe", "teacher", 32, 1.0),
      ("Liz", "teacher", 28, 2.0)
    )
    
    // Input molecule awaiting 3 inputs for `profession`, `age` and `score`
    val profAgeScore = m(Person.name.profession_(?).age_(?).score_(?))
    
    // Apply 3 input values (1 triple)
    profAgeScore.apply("doctor", 37, 1.0).get === List("Ann")
    i1

    Input value matching first input attribute (profession: String)

    i2

    Input value matching second input attribute (age: Int)

    i3

    Input value matching third input attribute (score: Double)

    conn

    Implicit Conn in scope

    returns

    Resolved molecule that can be queried

Concrete 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. def addNilClause(clauses: Seq[Clause], e: Var, kw: KW, v0: Var): Seq[Clause]
    Attributes
    protected
    Definition Classes
    InputMolecule
  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def bindSeqs(query: Query, inputRaw1: Seq[I1], inputRaw2: Seq[I2], inputRaw3: Seq[I3]): Query
    Attributes
    protected
  7. def bindValues(query: Query, inputTuples: Seq[(I1, I2, I3)]): Query
    Attributes
    protected
  8. def cardinality(ns: String, attr: String): Int
    Attributes
    protected
    Definition Classes
    InputMolecule
  9. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  10. def dataClause(e: String, kw: KW, enumPrefix: Option[String], arg: Any, i: Int): Seq[Clause]
    Attributes
    protected
    Definition Classes
    InputMolecule
  11. def deepNil(args: Seq[Any]): Boolean
    Attributes
    protected
    Definition Classes
    InputMolecule
  12. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  13. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  14. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  15. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  16. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  17. def isExpression(ns: String, attr: String): Boolean
    Attributes
    protected
    Definition Classes
    InputMolecule
  18. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  19. def isTacit(ns: String, attr: String): Boolean
    Attributes
    protected
    Definition Classes
    InputMolecule
  20. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  21. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  22. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  23. def pre[T](enumPrefix: Option[String], arg: T): Any
    Attributes
    protected
    Definition Classes
    InputMolecule
  24. def resolveAnd3(and3: And3[I1, I2, I3])(implicit conn: Conn): (Seq[I1], Seq[I2], Seq[I3])
    Attributes
    protected
  25. def resolveInput[T](query: Query, ph: Placeholder, inputs: Seq[T], ruleName: String = "rule1", unifyRule: Boolean = false): Query
    Attributes
    protected
    Definition Classes
    InputMolecule
  26. def resolveOr[I1](or: Or[I1]): Seq[I1]
    Attributes
    protected
    Definition Classes
    InputMolecule
  27. def resolveOr3(or: Or3[I1, I2, I3])(implicit conn: Conn): Seq[(I1, I2, I3)]
    Attributes
    protected
  28. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  29. def toString(): String
    Definition Classes
    AnyRef → Any
  30. def valueClauses[TT](e: String, kw: KW, enumPrefix: Option[String], args: TT): Seq[Clause]
    Attributes
    protected
    Definition Classes
    InputMolecule
  31. def varsAndPrefixes(query: Query): Seq[(Var, String)]
    Attributes
    protected
    Definition Classes
    InputMolecule
  32. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  33. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  34. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )

Inherited from InputMolecule

Inherited from MoleculeBase

Inherited from AnyRef

Inherited from Any

internal

Ungrouped