Fork me on GitHub
#datomic
<
2017-08-02
>
aklein317515:08:26

Hi everyone, we need to implement an auto-increment attribute, what are good patterns in datomic to do so?

val_waeselynck16:08:53

@U6H375J4T using a transaction function. The Datofu library provides an implementation, which you may use or take inspiration from https://github.com/vvvvalvalval/datofu#generating-unique-readable-ids

aklein317517:08:49

great, thank you

devth17:08:42

it's not possible to go back and add :db.part/tx metadata to a transaction, correct? realized this when attempting transactions with assertions plus tx metadata in the :db.part/tx partition, and noticing that if the assertion was already true, the tx metadata was not added

devth17:08:57

so, iiuc: if i want to put tx metadata (aka reified transactions) on a specific existing EAV the V must change. otherwise the assertion is ignored.

robert-stuttaford17:08:42

@devth you can annotate transactions after the fact; simply use its real id instead of a tempid

robert-stuttaford17:08:58

ie by querying [_ _ _ this] in datalog

robert-stuttaford17:08:45

:db.part/tx will always reference the in-flight transaction

robert-stuttaford17:08:23

literally did this today šŸ™‚ had to yank some scheduled mails, and forgot to document the ad-hoc transaction, so i had to find it and annotate it afterwards

devth17:08:02

awesome. yeah i was relying on the :db.part/tx referencing in-flight txes bit but hadn't considered looking up the tx-id after the fact

yedi20:08:20

if i have: [[?p :user/first-name ?fn][?p :user/last-name ?ln]] and I want to bind the concatenation of ?fn and ?ln to ?name, how would i go about doing that

kennethkalmer20:08:27

[[?p :user/first-name ?fn] [?p :user/last-name ?ln] [(clojure.core/str ?fn " " ?ln) ?name]] possibly

yedi20:08:51

woah that's so simple

hmaurer20:08:17

@kennethkalmer no need to prefix str either

kennethkalmer20:08:50

wasnā€™t sure if clojure.core was available, so thought Iā€™d be safe šŸ™‚

hmaurer20:08:10

@kennethkalmer yeah I just checked the doc to be sure; I had a doubt too šŸ™‚

kennethkalmer20:08:16

howzit everyone, I need to ask some advice on how to save a bunch of derived transactions to Datomic. Some background first: I have this abstraction of a data-set, which has a beginning and end date, and a type. these are prepopulated and saved to Datomic. Then I process a ton of other entities and calculate a bunch of derived entities from different entities. this is all simple and well, but I need to ā€œinjectā€ some additional transactions into the mix based on the transactions Iā€™ve seen pass by alreadyā€¦ By means of example, lets say I see the following (abbreviated) transactions pass by: [{:db/id -1 :foo/id 1} {:db/id -2 :foo/id 2} {:db/id -3 :foo/id 1}], I wanna concat onto that list [{:db/id 1 :data-set/ids [n m]} {:db/id 2 :data-set/ids [m]}] (where n & m are other eids). You see, nowhere else are entities 1 or 2 referenced in the transactions, so Iā€™m thinking Iā€™d need a transducer that accumulates the seen references to them and build up the additional transactions to concat onto the list. If I just slot them in directly as I encounter my ref Iā€™ll get an exception of trying to update the same entity twice in one transaction. My list of transactions also needs to be lazy, or Iā€™ll run out of memory. The list ends up in a generic function that batches the transactions. Iā€™ve already played with a simple transducer that simply counts the elements in a list and appends that number to the final results and it seems to work nicely when combined with sequence. Thing is, I just donā€™t know how to best handle this situation (even battling with some missing vocabulary here). Hope this rambling makes sense

kennethkalmer20:08:33

now Iā€™m wondering two things, 1) a reducing function that returns larger outputs than inputs is probably a smell, and 2) if this couldnā€™t be reworked with core.async to be more fluid

hmaurer20:08:13

@kennethkalmer I am pretty sure a reduce function which returns a large output than input is not a smell

hmaurer20:08:25

No idea about the rest though, sorry šŸ˜„

kennethkalmer20:08:07

think iā€™ll spend a bit of time wrapping my head around http://docs.datomic.com/best-practices.html#pipeline-transactions and core.async. maybe I can come up with something simpler while hopefully getting some feedback here