scalamolecule / molecule   1.1.0

Website GitHub

Non-blocking asynchronous domain-customizable database query language for Scala and Scala.js against the Datomic database.

Scala versions: 2.13 2.12 2.11
Scala.js versions: 1.x 0.6

Molecule is a non-blocking asynchronous domain-customizable database query language for Scala and Scala.js against the Datomic database.

Transactions and queries are type-safely built with the terms of your domain and works on both the jvm and js platform.

Visit to learn more or visit the Molecule forum


Your domain data model == your query language

Instead of squeezing your domain terms in between commands like SELECT name, age FROM Person etc, or other query constructs in other database languages, you directly use your domain terms as tokens to fetch data from the database:

This is possible since a schema is initially defined based on your domain data model:

trait Person {
  val name = oneString
  val age  = oneInt

When you compile your project with sbt compile, Molecule generates the necessary boilerplate code to allow writing the more intuitive query with type-inferred attributes. Since the types of each attribute name and age is encoded in the schema definition we'll also get typed data back from our query.

val personsWithAge: Future[List[(String, Int)]] =

No runtime overhead

Molecule transform molecules like to Datalog queries for Datomic. The returned untyped data from Datomic is then cast by Molecule to the expected Scala type.

All queries are prepared at compile time by macros. So there is no overhead at runtime when running the queries.

Client transactions and queries

Molecule is fully implemented on both the Scala jvm and Scala.js platforms. This means that you can transact and query data directly from the client side too with the same molecules that you would use on the server side. Molecule transparently handles marshalling data back and forth with one simple configuration.

Client molecules relieve you from having to manually define shared apis and make server implementations for shuttling data back and forth between client and server. Like QraphQL clients, just fully type-inferred.

Getting started

Sample projects

  1. git clone
  2. cd molecule-samples/molecule-basic
  3. sbt compile
  4. Open in your IDE
  5. Run tests and try adding more attributes...

Various sample projects show sbt setups for different contexts. You can also read the Setup section on the Molecule website.

Basic sbt setup (server side)

Add the following to your build files:




addSbtPlugin("org.scalamolecule" % "sbt-molecule" % "1.0.2")


lazy val yourProject ="app"))
    resolvers ++= Seq(
      "datomic" at "",
      "clojars" at "",
    libraryDependencies ++= Seq(
      "org.scalamolecule" %% "molecule" % "1.1.0",
      "com.datomic" % "datomic-free" % "0.9.5697" // or pro (see README_pro)
    moleculeSchemas := Seq("app") // paths to your schema definition files...

For Scala.js setups, please check the sample rpc projects or read the Setup section on the Molecule website.

Molecule is available at maven.


Marc Grue


Molecule is licensed under the Apache License 2.0