Molecule

Write powerful Datomic queries with the words of your domain:

Molecule is a Scala meta-DSL that translates “molecules” of your domain attributes to Datalog queries for Datomic - the database of immutable facts.

How does it work?

1

Define schema (once)

Our domain could have a Person with attributes name and age having a relationship to an Address so we define a schema for our domain:

trait Person {
  val name    = oneString
  val age     = oneInt
  val address = one[Address]
}
trait Address {
  val street = oneString
}
2

Compile (once)

> cd yourProjectRoot
> sbt compile

Molecule uses our schema as a template to generate some boilerplate code so that we can compose intuitive and powerful query molecules. This step is only needed when we create or change our schema.

3

Use molecules

Now we can insert data with molecules:

Person.name.age.Address.street insert List(
  ("Lisa", 20, "Broadway"),
  ("John", 22, "Fifth Avenue")
)

And retrieve data:

Person.name.age.Address.street.get === List(
  ("Lisa", 20, "Broadway"),
  ("John", 22, "Fifth Avenue")
)     

The implicit macros insert and get turns our molecules into type-safe Datalog inserts and queries at compile time. So there's no runtime overhead.

Try demo

  1. git clone https://github.com/scalamolecule/molecule-demo.git
  2. cd molecule-demo
  3. sbt compile
  4. Open in your IDE
  5. Run app - and build new molecules…

Next

Get started…

Read more