Molecule is a non-blocking asynchronous Scala platform to define your domain Data Model and use the defined terms and relationships as your type-inferred query language.
Molecule works on both the jvm and Scala.js platform. On the js platform you can fetch and transact data a bit like with GraphQL. But with molecules, all your domain terms are recognized by your IDE and fully type inferred so that any molecule query/transaction is guaranteed to be valid already when writing the code. Molecule then transparently makes a RPC call retrieving typed data without having to implement a shared interface on the server side.
The exact same molecule queries/transactions can be used on either the jvm or js side.
Molecule uses the powerful Datomic database that can model normal SQL tables, graphs, key-value and document stores. Even auditing data and time-awareness is a core built-in functionality of Datomic.
Scala macros transform a model of your domain data into query and transaction tokens that can be run directly against the database to save and retrieve typed data:
Domain Data Model
trait Person {
val name = oneString
val age = oneInt
val address = one[Address]
}
trait Address {
val street = oneString
}
Typed transactions and queries with the tokens of your domain model
for {
// insert data
_ <- Person.name.age.Address.street insert List(
("Lisa", 20, "Broadway"),
("John", 24, "5th Avenue")
)
_ <- Person.name.age.Address.street.get.map(_ ==> List(
("Lisa", 20, "Broadway"),
("John", 24, "5th Avenue")
))
} yield ()
Molecule is just a thin DataModel-to-query Scala translation layer on top of the heavy-weight Datomic database made by industry leaders like Rich Hickey, Stuart Halloway and more from Cognitect, the people behind the Clojure Language.
Datomic serves huge complex systems like Walmart, Nubank in Brasil and many more industries. If you want expressive power over a complex domain, Datomic and Molecule will safely serve you well.
git clone https://github.com/scalamolecule/molecule-samples.git
Open one of the projects in the sample projects repo in your IDE and run molecule queries with a ready-to-run in-memory database, no configuration needed. Make your own molecules and test straight away, or add new attributes to use. Or look at other database setups.