Si consiglia di utilizzare Tupelo Datomic per iniziare. Ho scritto questa libreria per semplificare la creazione dello schema Datomic e facilitare la comprensione, proprio come alludi alla tua domanda.
Ad esempio, supponiamo di voler tenere traccia delle informazioni per l'agenzia di spionaggio mondiale. Creiamo alcuni attributi che si applicano ai nostri eroi & furfanti (vedere il codice eseguibile in the unit test).
(:require [tupelo.datomic :as td]
[tupelo.schema :as ts])
; Create some new attributes. Required args are the attribute name (an optionally namespaced
; keyword) and the attribute type (full listing at http://docs.datomic.com/schema.html). We wrap
; the new attribute definitions in a transaction and immediately commit them into the DB.
(td/transact *conn* ; required required zero-or-more
; <attr name> <attr value type> <optional specs ...>
(td/new-attribute :person/name :db.type/string :db.unique/value) ; each name is unique
(td/new-attribute :person/secret-id :db.type/long :db.unique/value) ; each secret-id is unique
(td/new-attribute :weapon/type :db.type/ref :db.cardinality/many) ; one may have many weapons
(td/new-attribute :location :db.type/string) ; all default values
(td/new-attribute :favorite-weapon :db.type/keyword)) ; all default values
Per la: attributo di arma/tipo, vogliamo usare un tipo enumerato in quanto ci sono solo un numero limitato di scelte a disposizione dei nostri antagonisti:
; Create some "enum" values. These are degenerate entities that serve the same purpose as an
; enumerated value in Java (these entities will never have any attributes). Again, we
; wrap our new enum values in a transaction and commit them into the DB.
(td/transact *conn*
(td/new-enum :weapon/gun)
(td/new-enum :weapon/knife)
(td/new-enum :weapon/guile)
(td/new-enum :weapon/wit))
Creiamo alcuni antagonisti e carico li nel DB. Nota che stiamo usando solo valori Clojure e letterali semplici, e non dobbiamo preoccuparci di alcuna conversione Datomic specifica.
; Create some antagonists and load them into the db. We can specify some of the attribute-value
; pairs at the time of creation, and add others later. Note that whenever we are adding multiple
; values for an attribute in a single step (e.g. :weapon/type), we must wrap all of the values
; in a set. Note that the set implies there can never be duplicate weapons for any one person.
; As before, we immediately commit the new entities into the DB.
(td/transact *conn*
(td/new-entity { :person/name "James Bond" :location "London" :weapon/type #{ :weapon/gun :weapon/wit } })
(td/new-entity { :person/name "M" :location "London" :weapon/type #{ :weapon/gun :weapon/guile } })
(td/new-entity { :person/name "Dr No" :location "Caribbean" :weapon/type :weapon/gun }))
Divertiti! Alan
fonte
2015-07-14 22:13:11
grazie! Questo sembra risolvere la preoccupazione n. 2. Hai qualche consiglio su # 1? –