clojure - Change schema attribute cardinality based on another attribute -


i have following pseudo schemas:

a)

-- cost-schedule: fre494    -- periodic: false    -- type: fixed    -- value: 70.00    -- ccy gbp 

b)

-- cost-schedule: ghk999    -- periodic: true    -- period start: 01/04/2015    -- period end: 30/04/2015    -- type: promise    -- filled: false    -- value: 0.00    -- ccy: gbp 

i trying avoid kind of nasty hierarchy super class "cost-schedule" sub-classes "periodic" , "one-off". firstly, using clojure not oo. don't want fall liskov substitution trap.

so, newbie datomic, there way dynamically change schema attributes cardinality modified based on attribute value. in case, if periodic "false" don't need have period-start, period-end. if periodic "true" need enforce having values these attributes.

my gut says, not possible. if not, how can enforce in db? appears me if have explicitly validate transaction before submitting transactor defining schema outside of constraints of datomic doesn't appear wise, given many micro-systems writing/reading db , coordinating humans write 'correct' code difficult!

any on how overcome challenge gratefully received.

i see 2 sub-answers question.

the first datomic not define "objects". closer plain map. entity b has 3 fields entity not. fine , not controlled in way datomic. each attribute-value pair can added entity independently other entity. because 1 map has 4 entries, has no relationship map having 7 entries, if of keys in map in map b.

the 2nd sub-answer app must validation & integrity checking - datomic won't. there no analogue "unique not null" in sql, etc. however, datomic support database functions have chance abort transaction fails user-supplied test. so, 1 way of enforcing data integrity checks.

please check out tupelo datomic, library wrote make using datomic more effortless.


Comments