-
Notifications
You must be signed in to change notification settings - Fork 26
Step #1 : Scala DSL for Datomic Schema
sadache edited this page Oct 18, 2012
·
1 revision
[
;; person
{:db/id #db/id[:db.part/db]
:db/ident :person/name
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/fulltext true
:db/doc "A unique person name"
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :person/character
:db/valueType :db.type/string
:db/cardinality :db.cardinality/many
:db/doc "Traits of character"
:db.install/_attribute :db.part/db}
[:db/add #db/id[:db.part/user] :db/ident :person.character/stupid]
[:db/add #db/id[:db.part/user] :db/ident :person.character/clever]
[:db/add #db/id[:db.part/user] :db/ident :person.character/dumb]
[:db/add #db/id[:db.part/user] :db/ident :person.character/violent]
[:db/add #db/id[:db.part/user] :db/ident :person.character/weak]
]
implicit val uri = "datomic:mem://datomicspec2"
val _person = new NameSpace("person") {
val character = new NameSpace("person.character")
}
val schema = Schema (
// PERSON
_db/add(
_db/'id -> tempid( _db.part/'db ),
_db/'ident -> _person/'name,
_db/'valueType -> _db.typ/'string,
_db/'cardinality -> _db.cardinality/'one,
_db/'doc -> "\\"A unique person name\\"",
_db.install/'_attribute -> _db.part/'db
),
_db/add(
_db/'id -> tempid( _db.part/'db ),
_db/'ident -> _person/'character,
_db/'valueType -> _db.typ/'ref,
_db/'cardinality -> _db.cardinality/'many,
_db/'doc -> "\\"Traits of character\\"",
_db.install/'_attribute -> _db.part/'db
),
_db/add( tempid( _db.part/'user ), _db/'ident, _person.character/'stupid ),
_db/add( tempid( _db.part/'user ), _db/'ident, _person.character/'clever ),
_db/add( tempid( _db.part/'user ), _db/'ident, _person.character/'dumb ),
_db/add( tempid( _db.part/'user ), _db/'ident, _person.character/'violent ),
_db/add( tempid( _db.part/'user ), _db/'ident, _person.character/'weak )
)
println("created DB: "+createDatabase(uri))
val conn = connect(uri)
conn.createSchema(schema).map( r => println("Res:"+r) )