Repository navigation
v0.19.0 db namespace
All database specific modules have been unified in the db namespace in preparation for introducing molecule implementations for other data systems like GraphQL, Rest, etc.
Automatic code generation setup
The stb MoleculePlugin has been re-designed to offer command-based code generation without any setup.
Before, you had to tediously setup several sbt plugin settings in your build.sbt file to enable molecule boilerplate code generation and list the paths to your domain structure files.
But now you can simply enable the Molecule plugin with no additional settings!
.enablePlugins(MoleculePlugin)This is enouch to then generate Molecule boilerplate code with one of the following commands:
Generate sources
Generate all molecule boilerplate code with:
sbt moleculeGen
Molecule scans your project directories recursively with ScalaMeta for Domain Structure definition files and generates boilerplate code automatically. Code is generated in the src_managed/moleculeGen namespace to isolate it safely from code generated by other sbt plugins.
You can combine with other sbt actions:
sbt moleculeGen compile
sbt clean moleculeGen compile
// etc..
Omit code generation for some domain structure by setting the maxArity to 0:
object Foo extends DomainStructure(0) {
// definitions..
}Generate sources, compile and package
You can even package molecule code into jar files with a single command:
sbt moleculePackage
This
- generates sources,
- compiles,
- packages into class/source jar files in the
/libdirectory of your project and - clean up generated sources so that only the jars remain.
This is useful to avoid re-compiling the generated code when rebuilding your project.
The only caveat is that IntelliJ in some cases doesn't infer the type-rich generated code correctly although it's correct and compiles fine. So this option can be a good alternative when your domain structure has stabilized. And hopefully, IntelliJ will catch up soon.
Simplified backend setup with db choice
Molecule now offers an even easier way to test running molecule queries from ScalaJS against server backends and databases of your choice. A simple script lets you select databas/server combinations. So if you for instance want to run coreTests in the Molecule project:
git clone https://github.com/scalamolecule/molecule.git
cd molecule
sbt server/run
Then you are presented with choices of database and backend to be used for running the tests:
Please choose a database and a server backend to test the Molecule RPC API:
1 H2
2 MariaDB
3 MySQL
4 PostgreSQL
5 SQlite
6 Datomic
Database: 1
1 Armeria
2 Http4s
3 Netty
4 Pekko
5 Play
6 Vert.x
7 ZioHttp
Server: 3
Press ENTER to stop the server.
✅ Netty server running on http://localhost:8080 for H2
// running tests...
🛑 Shutting down server...
And in another process you run the tests from ScalaJS that will then call the Netty server to execute against a H2 database:
sbt dbDatalogDatomicJS/test
sbt dbSqlH2JS/test
sbt dbSqlMariaDBJS/test
sbt dbSqlMySQLJS/test
sbt dbSqlPostgreSQLJS/test
sbt dbSqlSQliteJS/test
MariaDB, MySQL, PostgreSQL and SQlite require docker to be running.
Since tests from ScalaJS fetch data asynchronously against the backend, we re-establish a new connection to an empty database on the backend for each test which is rather slow for MariaDB, MySQL, PostgreSQL. The in-memory database setups run fast, and live connections with no need for re-connection should run almost equally fast. Maybe there's a way to speed up the test setup, but it works and gives you the idea.