This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-25
Channels
- # announcements (4)
- # babashka (3)
- # beginners (79)
- # biff (4)
- # calva (17)
- # cider (18)
- # clj-kondo (21)
- # cljdoc (45)
- # cljs-dev (14)
- # cljsrn (9)
- # clojure (90)
- # clojure-europe (86)
- # clojure-italy (3)
- # clojure-nl (3)
- # clojure-portugal (1)
- # clojure-uk (9)
- # clojurescript (20)
- # code-reviews (23)
- # conjure (14)
- # cursive (12)
- # datascript (12)
- # emacs (5)
- # events (2)
- # fulcro (13)
- # gratitude (1)
- # holy-lambda (9)
- # lambdaisland (2)
- # malli (6)
- # nbb (1)
- # nextjournal (2)
- # nrepl (30)
- # off-topic (63)
- # pathom (1)
- # portal (24)
- # reagent (5)
- # reitit (13)
- # releases (2)
- # remote-jobs (1)
- # sci (90)
- # shadow-cljs (59)
- # spacemacs (5)
- # sql (13)
- # testing (20)
- # tools-build (17)
- # xtdb (27)
Typo in the docs? https://docs.xtdb.com/clients/clojure/#_db db-basis map should be ::xt/tx-id instead of ::xt/tx
I guess it's more the case of '{::xt/tx-id tx-n}' being undocumented, and the ::xt/tx key expecting a whole transaction map with a ::xt/tx-id in it
yep that's pretty much the case, the ::xt/tx map (in turn containing ::xt/tx-id) is the official™ way to use the API
Newbie question: What are people generally doing for xt/id
. Does it make sense to use a uuid here?
uuid is a generic choice for polymorphic documents (that is, a document can be of many types at the same time). Other options are using typed/namespaced compound keys like [:type id]
or {:type id}
. And yet another use key is using the id to force uniqueness, as a kind of an natural key like an email address of a user (do note that it would prevent people from changing their emails, so we make the address a separate document, with the email as id so that there is only one email address in the system, taking extra, super care to handle normalization with capitalization, + addresses etc)
Hey, I think a UUID is almost always the best answer, unless:
1. you can be confident about avoiding collisions in the ID space - in which case a Long
or short string may actually be okay (and probably is the most compact option!), or
2. you have an upstream ID - in which case use a keyword/map/string/URI can be a good idea
The id is anything serializable, that's why UUID works too (so it's really the java object, not just a string that happens to conform to uuid spec)
If one weren't use use an identifier such as an email address. How would indexing work should I want to lookup a user via email address
No problem at all. I really do appreciate both yours and @U899JBRPF’s input here
> Is space a concern being that "everything" is indexed? Ultimately, everything has its limits and you should definitely measure and experiment with your own realistic workloads. RocksDB does perform some compression of indexes though (which is tunable), and in general XT attempts to limit the amount of memory required to perform Datalog queries through lazy execution ...also disk is ~cheap 🙂 What size of data sets do you typically work with?
@U8ZQ1J1RR
> Other options are using typed/namespaced compound keys like [:type id]
or {:type id}
.
Out of curiosity, could you do a query of the sorts
{...
:in [?id]
:where
[[?e :xt/id [:a-type ?id]]
...}
in a destructuring manner?Easy to test that! And answer is no, you need to provide the whole value (the map) as the input
At the same time as I was testing, I noticed that I couldn't actually use vectors as ids, just "scalars" and maps 😦
Ignoring for a moment that vectors aren't valid ID types (so this exact example won't work), you can do this sort of thing though:
{...
:in [?id-v]
:where
[[(vector :a-type ?id-v) ?id]
[?e :xt/id ?id]
...}
And with map IDs (which are valid):
{...
:in [?id-v]
:where
[[(hash-set :a-type ?id-v) ?id]
[?e :xt/id ?id]
...}
Is there the concept of "entities" or does everything need to be specified in the pull expression? Sorry if I'm using too datomicy terms