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?


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

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.


Use molecules

Now we can insert data with molecules: insert List(
  ("Lisa", 20, "Broadway"),
  ("John", 22, "Fifth Avenue")

And retrieve data: === 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
  2. cd molecule-demo
  3. sbt compile
  4. Open in your IDE
  5. Run app - and build new molecules…


Get started…

Read more