Datomic dev-local/cloud

Minimal project setup to test a Cloud setup locally without connecting to a server.

import sbt.Keys._

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

lazy val app = project.in(file("app"))
    scalaVersion := "2.13.5",
    resolvers ++= Seq(
      "clojars" at "https://clojars.org/repo",

    libraryDependencies ++= Seq(
      "org.scalamolecule" %% "molecule" % "0.25.1",
      "com.datomic" % "dev-local" % "0.9.232"

    // 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. Create local client

implicit val conn = Datomic_DevLocal("datomic-samples").recreateDbFrom(SampleSchema, "sampledb")

Or, when the database has been created, only connect to it:

implicit val conn = Datomic_DevLocal("datomic-samples").connect("sampledb")

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))

// etc..

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.