Fork me on GitHub
#datascript
<
2018-10-19
>
Ho0man14:10:04

Hi, I have an object that has three fields, non of these fields are unique on their own but together they form a unique value that must not be replicated, how can I achieve this in datascript ?

isak14:10:17

@ho0man have you tried just putting them in a vector or map, and assign that an an attribute value, then doing the normal thing to make that attribute unique in the schema?

Ho0man15:10:51

Thanks @U08JKUHA9 but the values themselves may point to other entities.

Ho0man15:10:12

{:conversion/buy         {:db/valueType :db.type/ref
                            :db/cardinality :db.cardinality/one}
   :conversion/sell        {:db/valueType :db.type/ref
                            :db/cardinality :db.cardinality/one}
   :conversion/account     {:db/valueType :db.type/ref
                            :db/cardinality :db.cardinality/one}
   ;;----------------------------------------;;
   :arbitrage-unit/conversion  {:db/valueTpe  :db.type/ref
                                :db/unique    :db.unique/value}
   :arbitrage-unit/value       {:db/cardinality :db.cardinality/one
                                :db/doc "A arbitrage-unit's value limit"}
   :arbitrage-unit/priority    {:db/cardinality :db.cardinality/one}
   :arbitrage-unit/min-ratio   {:db/cardinality :db.cardinality/one}
   :arbitrage-unit/max-ratio   {:db/cardinality :db.cardinality/one}
   ;;----------------------------------------;;
   :equity/isin            {:db/unique    :db.unique/value}
   ;;----------------------------------------;;
   :account/name           {:db/unique    :db.unique/value}
   :account/code           {:db/unique    :db.unique/value}
   ;;----------------------------------------;;
   }

Ho0man15:10:37

This is my schema right now, and the :conversion is the entity that is supposed to be unique for each combination of values for its field.

metasoarous17:10:32

This is not possible right now unfortunately. You could use a transaction function to update these entities, and have the transaction function check to make sure the combined attributes are unique. But that doesn't stop another transaction from violating the desired constraint.

Ho0man17:10:54

Thanks alot @U05100J3V, a quick question though, what differences make this impossible in datascript compared to datomic? (or is a problem on that as well)

timgilbert17:10:50

Composite keys are also not implemented in datomic, fwiw

metasoarous18:10:09

Correct; You'd have to use transaction functions in Datomic as well.

metasoarous18:10:12

@tonsky Hey! Congrats on the Clojurists Together funding!

🎉 44