Skip to content
yokolet edited this page Apr 24, 2013 · 5 revisions

Datomic distribution has a great sample maintained by Seattle user group. This document explains how to run the Seattle example on Diametric gem. This document assumes Peer-based API on JRuby. REST-API is a subset of Peer API and some of methods using here are not supported.

  1. Schema definition

    class Seattle
      include Diametric::Entity
      include Diametric::Persistence::Peer
    
      attribute :name, String, :cardinality => :one, :fulltext => true, :doc => "A community's name"
      attribute :url, String, :cardinality => :one, :doc => "A community's url"
      attribute :neighborhood, Ref, :cardinality => :one, :doc => "A community's neighborhood"
      attribute :category, String, :cardinality => :many, :fulltext => true, :doc => "All community categories"
      attribute :orgtype, Ref, :cardinality => :one, :doc => "A community orgtype enum value"
      attribute :type, Ref, :cardinality => :one, :doc => "A community type enum value"
      enum :orgtype, [:community, :commercial, :nonprofit, :personal]
      enum :type, [:email_list, :twitter, :facebook_page, :blog, :website, :wiki, :myspace, :ning]
    end
    
    class Neighborhood
      include Diametric::Entity
      include Diametric::Persistence::Peer
    
      attribute :name, String, :cardinality => :one, :unique => :identity, :doc => "A unique neighborhood name(upsertable)"
      attribute :district, Ref, :cardinality => :one, :doc => "A neighborhood's district"
    end
    
    class District
      include Diametric::Entity
      include Diametric::Persistence::Peer
    
      attribute :name, String, :cardinality => :one, :unique => :identity, :doc => "A unique district name (upsertable)"
      attribute :region, Ref, :cardinality => :one, :doc => "A district region enum value"
      enum :region, [:n, :ne, :e, :se, :s, :sw, :w, :nw]
    end

    This definitions is equivalent to Datomic schema below:

    [
     ;; seattle
    
     {:db/id #db/id[:db.part/db]
      :db/ident :seattle/name
      :db/valueType :db.type/string
      :db/cardinality :db.cardinality/one
      :db/fulltext true
      :db/doc "A community's name"
      :db.install/_attribute :db.part/db}
    
     {:db/id #db/id[:db.part/db]
      :db/ident :seattle/url
      :db/valueType :db.type/string
      :db/cardinality :db.cardinality/one
      :db/doc "A community's url"
      :db.install/_attribute :db.part/db}
    
     {:db/id #db/id[:db.part/db]
      :db/ident :seattle/neighborhood
      :db/valueType :db.type/ref
      :db/cardinality :db.cardinality/one
      :db/doc "A community's neighborhood"
      :db.install/_attribute :db.part/db}
    
     {:db/id #db/id[:db.part/db]
      :db/ident :seattle/category
      :db/valueType :db.type/string
      :db/cardinality :db.cardinality/many
      :db/fulltext true
      :db/doc "All community categories"
      :db.install/_attribute :db.part/db}
    
     {:db/id #db/id[:db.part/db]
      :db/ident :seattle/orgtype
      :db/valueType :db.type/ref
      :db/cardinality :db.cardinality/one
      :db/doc "A community orgtype enum value"
      :db.install/_attribute :db.part/db}
    
     {:db/id #db/id[:db.part/db]
      :db/ident :seattle/type
      :db/valueType :db.type/ref
      :db/cardinality :db.cardinality/one
      :db/doc "A community type enum value"
      :db.install/_attribute :db.part/db}
    
     ;; community/org-type enum values
     [:db/add #db/id[:db.part/user] :db/ident :seattle.orgtype/community]
     [:db/add #db/id[:db.part/user] :db/ident :seattle.orgtype/commercial]
     [:db/add #db/id[:db.part/user] :db/ident :seattle.orgtype/nonprofit]
     [:db/add #db/id[:db.part/user] :db/ident :seattle.orgtype/personal]
    
     ;; community/type enum values
     [:db/add #db/id[:db.part/user] :db/ident :seattle.type/email-list]
     [:db/add #db/id[:db.part/user] :db/ident :seattle.type/twitter]
     [:db/add #db/id[:db.part/user] :db/ident :seattle.type/facebook-page]
     [:db/add #db/id[:db.part/user] :db/ident :seattle.type/blog]
     [:db/add #db/id[:db.part/user] :db/ident :seattle.type/website]
     [:db/add #db/id[:db.part/user] :db/ident :seattle.type/wiki]
     [:db/add #db/id[:db.part/user] :db/ident :seattle.type/myspace]
     [:db/add #db/id[:db.part/user] :db/ident :seattle.type/ning]
    
     ;; neighborhood
     {:db/id #db/id[:db.part/db]
      :db/ident :neighborhood/name
      :db/valueType :db.type/string
      :db/cardinality :db.cardinality/one
      :db/unique :db.unique/identity
      :db/doc "A unique neighborhood name (upsertable)"
      :db.install/_attribute :db.part/db}
    
     {:db/id #db/id[:db.part/db]
      :db/ident :neighborhood/district
      :db/valueType :db.type/ref
      :db/cardinality :db.cardinality/one
      :db/doc "A neighborhood's district"
      :db.install/_attribute :db.part/db}
    
     ;; district
     {:db/id #db/id[:db.part/db]
      :db/ident :district/name
      :db/valueType :db.type/string
      :db/cardinality :db.cardinality/one
      :db/unique :db.unique/identity
      :db/doc "A unique district name (upsertable)"
      :db.install/_attribute :db.part/db}
    
     {:db/id #db/id[:db.part/db]
      :db/ident :district/region
      :db/valueType :db.type/ref
      :db/cardinality :db.cardinality/one
      :db/doc "A district region enum value"
      :db.install/_attribute :db.part/db}
    
     ;; district/region enum values
     [:db/add #db/id[:db.part/user] :db/ident :district.region/n]
     [:db/add #db/id[:db.part/user] :db/ident :district.region/ne]
     [:db/add #db/id[:db.part/user] :db/ident :district.region/e]
     [:db/add #db/id[:db.part/user] :db/ident :district.region/se]
     [:db/add #db/id[:db.part/user] :db/ident :district.region/s]
     [:db/add #db/id[:db.part/user] :db/ident :district.region/sw]
     [:db/add #db/id[:db.part/user] :db/ident :district.region/w]
     [:db/add #db/id[:db.part/user] :db/ident :district.region/nw]
     ]
Clone this wiki locally