Fork me on GitHub
#datomic
<
2017-02-18
>
wei00:02:11

are there any idiomatic ways to represent an ordered list in datomic? more specifically, a queue

pesterhazy00:02:56

either by adding a "position" attribute, or by using a linked list

misha01:02:34

@pesterhazy linked list? like here? http://jmhofer.johoop.de/datomic/2012/08/18/linked-lists-in-datomic.html

[{:db/id #db/id[:db.part/db], :db/ident :content/name, ...
 {:db/id #db/id[:db.part/db], :db/ident :linkedList/head, ...
 {:db/id #db/id[:db.part/db], :db/ident :linkedList/tail, ...

wei02:02:14

there’s also this, evaluating it now https://github.com/dwhjames/datomic-linklist

misha02:02:42

I keep indexes in a list in a separate attribute.

{:x/ys #{1 2 3}
 :x/ys-order #{{:o/id 1 :o/idx 0}
               {:o/id 2 :o/idx 2}
               {:o/id 3 :o/idx 1}}}

misha02:02:06

(ys in my case are not components of x, and can have multiple "parent" collections)

wei02:02:30

only annoying thing is popping off the queue requires reshuffling all idxs

misha02:02:18

you can just grow idxs and pop the lowest one

misha02:02:24

but for queues linked list might be more suitable. I need to be able to swap/shuffle elements, so this :x/ys-order works for me

wei02:02:02

makes sense

misha02:02:14

it also helps with recursive pull patterns, if you happen to have parent/child of the same "type".

misha02:02:13

previously I had a wrapper object instead, so it looked like :x -> :w -> :y

misha02:02:54

pull patterns and queries were nightmare unpleasant

wei02:02:55

that’s a good consideration. wrappers do make queries more annoying

wei02:02:51

also thought about serializing to EDN a vector of uuids. makes some things easier, but then it’s not queryable

misha02:02:54

true, + extra special step

pesterhazy09:02:30

also storing blobs is not efficient in Datomic

pesterhazy09:02:36

once they're getting a bit bigger