Other databases vs. Molecule

Every database/abstraction layer has its strengths and weaknesses and we’ll try here to compare existing systems with Molecule with some examples of how they accomplish similar tasks.

Others consume, Molecule declares data structures

Many systems lets you define data objects matching your domain that are then consumed by the host language (Scala) in combination with DSLs.

If we take Slick for instance we could say that it “consumes” the data objects coffees and suppliers in this Scala sequence comprehension:

// Slick
val implCrossJoin = for {
  c <- coffees
  s <- suppliers
} yield (c.name, s.name)

Whereas in Molecule, we only declare which attributes we are interested in. Molecule attributes themselves form the query - they are not consumed by an outer construct. That way, the domain terms directly form the query without additional keywords and constructs:

// Molecule
val coffeeSupliers = Coffees.name.Suppliers.name.get

We get the exact same type-inferred result back, a List[(String, String)]

Squeryl also consumes data objects, now in a DSL construct:

// Squeryl
def songs = from(MusicDb.songs)(s => where(s.artistId === id) select(s))

In Molecule we don’t need to use keywords like from, where and select (apart from the final get method). We instead get song entities (e) filtered by Artist by simply applying a required value directly to the artist attribute:

// Molecule
val songs = Song.e.artist(id).get

More databases to compare…

Over time we’ll compare Molecule with as many database systems as possible. Those not linked yet below are on our wish list:

Please feel free to suggest a tutorial to “translate” to Molecule…