datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
2018-10-19T14:43:04.000100Z

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 ?

isak 2018-10-19T14:57:17.000100Z

@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?

timgilbert 2018-10-22T17:58:50.000100Z

Composite keys are also not implemented in datomic, fwiw

2018-10-22T18:40:24.000100Z

Thanks

2018-10-23T18:08:09.000100Z

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

2018-10-19T15:00:51.000100Z

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

2018-10-19T15:02:12.000100Z

{: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}
   ;;----------------------------------------;;
   }

2018-10-19T15:03:37.000100Z

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.

2018-10-19T17:01:32.000100Z

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.

2018-10-19T17:08:54.000100Z

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

2018-10-19T18:12:12.000100Z

@tonsky Hey! Congrats on the Clojurists Together funding!

11🎉
2018-10-19T18:46:07.000100Z

link?

2018-10-19T18:58:30.000100Z

that's exciting.