Fork me on GitHub
#xtdb
<
2020-10-30
>
Jorin09:10:29

hi there 🙂 I just updated https://github.com/jorinvo/crux-typescript-healthcare-demo/commit/b404a1600987b205fc5f4caf0cea522c4edf5923. In general that worked pretty smooth. The https://github.com/juxt/crux/blob/20.09-1.12.0/docs/topo-migration.adoc was super helpful, thanks for that! One thing that confused me was, that the migration guide uses a backtick for module references. Using that in crux.edn gave me an error:

Execution error at crux.system/read-opts (system.clj:26).
Invalid leading character: 
` I https://www.opencrux.com/reference/20.09-1.12.1/rocksdb.html and they use a single quote. That gave me a different error:
Execution error (FileNotFoundException) at crux.system.ModuleRef/fn (system.clj:100).
Could not locate 'crux/rocksdb__init.class, 'crux/rocksdb.clj or 'crux/rocksdb.cljc on classpath.
What worked was to use the symbol directly. I guess both docs are not targeted at users of the crux.edn file, but this took me a bit to figure out 😅

jarohen09:10:52

hey @U8ZN5EHGU - glad to hear you got to the bottom of it Ah, of course - yes, the values don't need to be quoted in crux.edn because they're already quoted, essentially, by virtue of being EDN rather than Clojure. We'll have a think on how we can best represent this in the docs - thanks 🙂

Jorin09:10:11

one option would be to have a 3rd tab in the docs: JSON/Clojure/EDN.. not sure if that is too much to maintain 😄

jaju12:10:47

I think a simple but prominent one-liner will be helpful - I too ran into this very initially (mentally not distinguishing between the sample, in-code config and what goes into some config.edn), but soon figured out.

Jorin14:10:04

yes, also sounds good 🙂

codemartin20:10:53

If you want to amend a document (such as UPDATE in SQL), where you change only the value of one or more key/vals, but the rest of the document is kept, is that possible without first getting the whole of the document from crux, and then resubmitting the whole thing in a new transaction? Explaination:

(crux.api/submit-tx node
                    [[:crux.tx/put {:crux.db/id :temp
                                    :dont-change-me "yo"
                                    :some-bool? false}]])
(crux.api/q (crux.api/db node)
            {:find '[?id ?dont-change-me
                     ?some-bool?]
             :where '[[?id :crux.db/id :temp]
                      [?id :dont-change-me ?dont-change-me]
                      [?id :some-bool? ?some-bool?]]})
;; => #{[:temp "yo" true]}
And then I'll submit a transaction to update :some-bool? but not to care about :dont-change-me
(crux.api/submit-tx node
                    [[:crux.tx/put {:crux.db/id :temp
                                    ;; :dont-change-me "yo"
                                    :some-bool? true}]])
And let's have another look
(crux.api/q (crux.api/db node)
            {:find '[?id ?dont-change-me
                     ?some-bool?]
             :where '[[?id :crux.db/id :temp]
                      [?id :dont-change-me ?dont-change-me]
                      [?id :some-bool? ?some-bool?]]})
;; => #{}
but rather
(crux.api/q (crux.api/db node)
            {:find '[?id ;; ?dont-change-me
                     ?some-bool?]
             :where '[[?id :crux.db/id :temp]
                      ;; [?id :dont-change-me ?dont-change-me]
                      [?id :some-bool? ?some-bool?]]})
;; => #{[:temp true]}
So that's my question. Can you update a document that is already existing, without removing all information kept in it but the field you wish you update?

refset23:10:56

Hi 🙂 there's no native (core) API for doing an update/patch like this in Crux, although if you want to recreate those kinds of transactional semantics you can use a transaction function, e.g. https://gist.github.com/refset/a00be06443bc03ccc84a2874af3cdb8a#file-txfns-clj-L10-L31 - just be aware that it will still be resolved to documents under the hood. There was a recent thread about this that you may find interesting for more context https://clojurians-log.clojureverse.org/crux/2020-10-17/1602949393.166100

codemartin21:10:16

I guess in datomic it'd be called replace