Datomic Peer (pro), in-mem

Minimal project setup to test using Molecule with a starter/pro Datomic Peer in-memory database (protocol: mem).

import sbt.Keys._

lazy val demo = project.in(file("."))
  .settings(name := "molecule-datomic-peer-pro-mem")

lazy val app = project.in(file("app"))
    scalaVersion := "2.13.4",
    resolvers ++= Seq(
      "clojars" at "https://clojars.org/repo",
      "my.datomic.com" at "https://my.datomic.com/repo"
      Downloading Datomic Starter/Pro requires authentication of your license:
      Create a ~/.sbt/.credentials file with the following content:

        realm=Datomic Maven Repo

      Then let sbt provide your secret credentials:
    credentials += Credentials(Path.userHome / ".sbt" / ".credentials"),

    libraryDependencies ++= Seq(
      "org.scalamolecule" %% "molecule" % "0.24.0",
      "com.datomic" % "datomic-pro" % "1.0.6222"

    // Important to exclude fee version when using pro to avoid clashes with pro version
    excludeDependencies += ExclusionRule("com.datomic", "datomic-free"),

    // path to domain model directory
    moleculeDataModelPaths := Seq("app"),

    // Generate Molecule boilerplate code with `sbt clean compile -Dmolecule=true`
    moleculePluginActive := sys.props.get("molecule") == Some("true"),

    // Let IDE detect created jars in unmanaged lib directory
    exportJars := true

1. Connect to Peer

Connect, recreate in-memory database and get database connection

implicit val conn = Datomic_Peer.recreateDbFrom(SampleSchema) 

Since we are not persisting the database, we let Molecule create a random database name. We don’t need to supply the default “mem” protocol either. So this is really simple.

If you need persisting data, please see other storage options or have a look at one of the other sample projects.

2. Make molecules

Having an implicit connection in scope, we can start transacting and querying sampledb with molecules:

// Transact

// Query
assert(Person.name.age.get.head == ("John", 24))

Add/change definitions in the SampleDataModel and run sbt clean compile -Dmolecule=true in your project root to have Molecule re-generate boilerplate code. Then you can try out using your new attributes in new molecules in SampleApp.