This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-11
Channels
- # beginners (132)
- # boot (2)
- # cider (17)
- # cljs-dev (6)
- # cljsrn (24)
- # clojure (134)
- # clojure-austin (2)
- # clojure-dusseldorf (11)
- # clojure-france (1)
- # clojure-greece (27)
- # clojure-italy (17)
- # clojure-madison (1)
- # clojure-russia (31)
- # clojure-serbia (1)
- # clojure-sg (2)
- # clojure-spec (30)
- # clojure-uk (66)
- # clojurescript (73)
- # core-async (2)
- # cursive (8)
- # data-science (2)
- # datomic (23)
- # dirac (8)
- # emacs (18)
- # gsoc (1)
- # hoplon (36)
- # immutant (26)
- # leiningen (6)
- # off-topic (21)
- # om (19)
- # onyx (6)
- # other-languages (1)
- # pedestal (3)
- # proton (2)
- # random (1)
- # re-frame (1)
- # reagent (2)
- # remote-jobs (2)
- # ring-swagger (8)
- # rum (21)
- # slack-help (1)
- # spacemacs (4)
- # specter (16)
- # untangled (6)
Does anyone know the best practice for naming booleans in Datomic? Is it possible to follow the Clojure practice of using “?” at the end, or are you using an “is-” pre-fix, or is some other approach preferred?
james: I don't know if it's a best practice or not, but we've been using :user/disabled?
and the like for boolean attributes and I like the way it looks. It also destructures nicely into local bindings named disabled?
which seems like a plus: (let [{:keys [:user/disabled?]} query-result] ... (if disabled? foo bar))
@U08QZ7Y5S Thanks for letting me know, and I like your approach.
I have some related entities in datomic:
{:db/id 1
:related
({:db/id 2 :name "B"})}
I’d like to do two different things to it. Replace the related entities (and retract the old ones):
{:db/id 1
:related
({:db/id 3 :name "C"}
{:db/id 4 :name "D"})}
and remove all related entities:
{:db/id 1
:related ()} ;; yes, I'm aware this wouldn't technically exist anymore. I'm just printing it here to help describe what I'm looking for.
I tried replacing them like this:
(d/transact conn [{:db/id 1
:related updates}])
but that just appended new ones.
What’s the best way to go about doing these in datomic? Do I really need to query the db again to find all the related items and retract them manually? If so, can I do that in a transaction somehow so that I can be sure another process doesn’t add another related entity at the same time?Datomic only transacts changes (add/retract), not replacements (make the entity look like this). You have to emit retractions if you want to remove items
You can do this by query, compare, retract in the peer, but that is subject to race conditions (by the time transaction arrives at the txor, something else may have been added)
You can also use a db function like this: https://gist.github.com/favila/8ce31de4b2cb04cf202687c6a8fa4c94 (There are other ones out there which are a little smarter)
that eliminates the race since the work happens in the transactor. But you still need to think about who "wins" if different peers assert different things independently
e.g., do you really always want "last writer wins" semantics at entity+attribute granularity?
Whatever policy you finally choose you can write transaction function interfaces to enforce them
Are there any of these functions built in or do you always need to write them yourself? (a quick search yielded no results)
Sorry guys, one other question. I am trying to do a restore-db to a ddb-local instance, and the writes to the transactor are happening so fast I am losing the heartbeat. I am experimenting with the -Ddatomic.s3BackupConcurrency
and -Ddatomic.backupPaceMsec
system properties. Are these the right things to be tinkering with?
@bmaddy you may be interested in Datofu https://github.com/vvvvalvalval/datofu#resetting-to-many-relationships
(disclaimer: I'm the author)
@val_waeselynck Thanks--I’ll check that out!
james: I don't know if it's a best practice or not, but we've been using :user/disabled?
and the like for boolean attributes and I like the way it looks. It also destructures nicely into local bindings named disabled?
which seems like a plus: (let [{:keys [:user/disabled?]} query-result] ... (if disabled? foo bar))