Fork me on GitHub
#datomic
<
2017-01-28
>
shaun-mahood02:01:49

Has anyone worked on a Datomic system that links to something like PostGIS? I’m thinking about keeping all the important info in Datomic and linking to the location data, but I’m wondering if anyone else has given any thought to how to keep that link as immutable as possible or any other real life gotchas that I haven’t considered yet.

Ethan Miller14:01:35

Where above it says taxonomy read “schema"

alqvist15:01:17

If I have an attribute :event/order declared as :db.unique/value is there any way of asking datomic for a set of all attribute values?

alqvist15:01:58

With good performance. Want to use it for autocompletion

alqvist15:01:34

There are magnitudes more events than orders

alqvist16:01:44

Not :db.unique/value since that wouldn't work... The question is more if I can get the set of values in a fast way

alqvist16:01:35

I could make another entity :order and do references, but it seems kind of wasteful

robert-stuttaford17:01:07

@alqvist Datalog? [:find ?order :where [_ :event/order ?order]] or transducer + datoms index? (into #{} (comp (map :v) (distinct)) (seq (d/datoms db :avet :event/order)))

robert-stuttaford17:01:33

doubt you’d find a faster way than one of those two

robert-stuttaford17:01:32

if you have a LOT of usages, you could maintain a set separately as you discover new ones. so, move the work to transactor functions or the like.

robert-stuttaford17:01:12

my code assumes you’re :db/index true or :db/unique

pesterhazy17:01:18

@ezmiller77 well what is the transaction?

Ethan Miller17:01:44

@pesterhazy you mean what was the actual transact call? It looked like this:

(def arb-tx (-> (io/resource "schemas/arb.edn")
                (read-all)
                (first)))

(pprint (<!! (client/transact conn {:tx-data arb-tx})))
where “schemas/arb.edn” is the schema listed in that stackoverflow question. I guess I should have included that in the Q.

pesterhazy17:01:16

Try calling the transactions manually from the repl

pesterhazy17:01:55

why do you call first there?

pesterhazy17:01:11

tx-data is supposed to be a collection of txs

Ethan Miller17:01:40

just because (read-all) spits out a vector

Ethan Miller17:01:26

so arb-tx looked like: [[ <taxonomy definition maps> ]]

Ethan Miller17:01:40

instead of [ <taxonomy definition maps> ]

Ethan Miller17:01:19

read-all looks like:

Ethan Miller17:01:25

(defn read-all
  "Read all forms in f, where f is any resource that can
   be opened by io/reader"
  [f]
  (Util/readAll (io/reader f)))

Ethan Miller17:01:32

(copied from day-of-datomic)

pesterhazy18:01:01

do you see the same error when you run the code from the repl?

Ethan Miller18:01:06

although removing first, I get this error, also totally inscrutable to me:

{:datomic.client-spi/request-id "9c59aa1c-6127-45fd-87b2-afce72223ce1",
 :cognitect.anomalies/category :cognitect.anomalies/incorrect,
 :cognitect.anomalies/message
 ":db.error/not-a-data-function Unable to resolve data function: {:db/id {:idx -1000000, :part :db.part/db}, :db/ident :arb/title, :db/unique :db.unique/identity, :db/valueType :db.type/string, :db/cardinality :db.cardinality/one, :db/fulltext true, :db/index true, :db.install/_attribute :db.part/db}",
 :dbs
 [{:database-id "datomic:",
   :t 1004,
   :next-t 1009,
   :history false}]}

Ethan Miller18:01:38

i haven’t been able to figure out how to run it from the repl yet b/c I haven’t figured out how to do the edn file import from there

pesterhazy18:01:23

why don't you try transacting a simple map first?

pesterhazy18:01:35

then add stuff one by one

Ethan Miller18:01:53

not sure what you mean by a simple map?

pesterhazy18:01:54

@(d/transact (rdc) [{:db/id (d/tempid :db.part/user) :db/doc "hello"}])

pesterhazy18:01:12

I guess from the client api it looks a bit different

Ethan Miller18:01:00

oh well that i’ve done before

Ethan Miller18:01:08

but i can try it again if you think it’s helpful.

pesterhazy18:01:45

well if you start with that and then add things bit by bit, I think you may be able to narrow in on the problem

Ethan Miller18:01:09

the command you have there is using the datomic api right?

Ethan Miller18:01:16

as opposed to the client?

Ethan Miller18:01:05

damn, can’t even manage to enter that edn structure into the repl

Ethan Miller18:01:16

gonna have to pick this up later.

Ethan Miller18:01:27

thanks for trying to help @pesterhazy

Ethan Miller18:01:35

the first line there in the schema defn :db/id #db/id [:db.part/db], is being interpreted as a function, which now that i look at it makes sense, so I get this error:

user=> (def arb-title [{:db/id #db/id [:db/part/db]}])
IllegalStateException Attempting to call unbound fn: #'datomic.db/id-literal  clojure.lang.Var$Unbound.throwArity (Var.java:43)
RuntimeException Unmatched delimiter: }  clojure.lang.Util.runtimeException (Util.java:221)
RuntimeException Unmatched delimiter: ]  clojure.lang.Util.runtimeException (Util.java:221)
RuntimeException Unmatched delimiter: )  clojure.lang.Util.runtimeException (Util.java:221)

alqvist18:01:30

@robert-stuttaford Datalog. Probably going with maintaining a separate set since there might be millions of events.

alqvist18:01:39

thanks for the answer

pesterhazy19:01:53

@ezmiller77 that ain't right: :db/part/db