Build intuitive queries with your domain terms
Person.name.age.Address.street.get.map { tuples =>
tuples.head ==> ("Lisa", 20, "Broadway")
}
Person.name.age.Address.street.getObjs.map { objects =>
val obj = objects.head
obj.name ==> "Lisa"
obj.age ==> 20
obj.Address.street ==> "Broadway"
}
Person.name.age.Address.street.getJson.map { json =>
json ==>
"""{
| "data": {
| "Person": [
| {
| "name": "Lisa",
| "age": 20,
| "Address": {
| "street": "Broadway"
| }
| }
| ]
| }
|}""".stripMargin
}
Transact and fetch data with molecules transparently from the js platform
without shared interfaces and sever implementations.
Read more..
// js
val personApi = ... // rpc setup
personApi.personAge("Lisa").map(age =>
body.appendChild(
div("Lisa's age: " + age).render
)
)
// shared
trait PersonApi {
def personAge(name: String): Future[Int]
}
// jvm
object PersonImpl extends PersonApi {
def personAge(name: String) = {
Person.name_(name).age.get.map(_.head)
}
}
// js
Person.name_("Lisa").age.getObj.map(lisa =>
body.appendChild(
div("Lisa's age: " + lisa.age).render
)
)
Use a Data Model of your Domain to build
type-inferred molecules for both transactions and queries
trait Person {
val name = oneString
val age = oneInt
val address = one[Address]
}
trait Address {
val street = oneString
}
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")
))
Transact and query uniformly with your molecule api against any of the three
m
|
Molecule |
|
Datomic® |
|
|
git clone https://github.com/scalamolecule/molecule-samples.git