Fork me on GitHub
#datomic
<
2021-11-10
>
Kris C08:11:38

Hello, is it possible to have (define) a composite tuple if one of the keys (tuple attributes) has a :db.cardinality/many ?

Benjamin13:11:45

where can I read on the difference between onprem and cloud?

kenny15:11:43

Is it expected that you cannot pull from the same eid in two locations in the :find of a query?

(d/q '[:find (pull ?e [:db/doc]) (pull ?e [:db/ident])
       :where
       [?e :db/ident :db/cardinality]]
  (d/db conn))
Execution error (ArrayIndexOutOfBoundsException) at datomic.core.datalog/fn$project (datalog.clj:560).
Index 1 out of bounds for length 1

Lennart Buit07:11:49

I’ve been bitten by this before too

Lennart Buit07:11:27

You can also not do {:find [?e (pull ?e [*])] …}

kenny15:11:31

Creating a new var name lets you do it:

(d/q '[:find (pull ?e [:db/doc]) (pull ?e2 [:db/ident])
       :where
       [?e :db/ident :db/cardinality]
       [(identity ?e) ?e2]]
  (d/db conn))
=>
[[#:db{:doc "Property of an attribute. Two possible values: :db.cardinality/one for single-valued attributes, and :db.cardinality/many for many-valued attributes. Defaults to :db.cardinality/one."}
  #:db{:ident :db/cardinality}]]

Benjamin16:11:40

I'm gathering test statistics in my database, e.g. what errors were logged during a test run (so we can have stats about our tests). Would you create idents for each error type and then have an "error log" entity that has a ref attribute. Or would you make the error type something like a string?

favila16:11:11

(s/string/keyword/)

Benjamin16:11:38

s = symbol?

favila16:11:11

sorry that’s sed. I’m saying why consider a string when you could use an actual keyword type

Benjamin16:11:42

yea makes way more sense

favila16:11:34

Advantage refs/enums: you can rename them easily, you can attach metadata to their entities, they can be semi-closed, self-describing (in db) enumerated sets (i.e. open, but ceremony and thought required to make new ones)

✔️ 1
favila16:11:04

Disadvantage: d/pull api returns them as entities not keywords, which can be annoying if you want to represent them as keyword values in code. You shouldn’t have a very large number (tens of thousands) of idents for performance reasons. You need to change schema to add them, which isn’t good if you don’t control the set

favila16:11:35

using keywords instead is basically the opposite tradeoffs vs the above

Benjamin16:11:52

thanks. I get a bit the feeling for starters keywords is fine

favila16:11:53

If you use a keyword, you can still use an attribute predicate to enforce the set if you need (e.g. guard against typos), but now enlarging the set requires a deploy, not just a schema change

👍 1
bhurlow21:11:33

Any Datomic users have strategies for generating good data sets for testing? Anyone using generative testing against the Datomic schema?

octahedrion09:11:12

I've used clojure.test.check.generators with Datomic to do property based testing of databases over time (a single database changing over time) and "space" (a space of databases with different variations) with dev-local and d/with and it works well

👍 1