This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-12-26
Channels
- # announcements (4)
- # babashka (5)
- # beginners (11)
- # clj-kondo (4)
- # clojure-bay-area (1)
- # clojure-dev (8)
- # clojure-europe (4)
- # clojure-norway (10)
- # conjure (2)
- # datomic (12)
- # emacs (3)
- # hyperfiddle (5)
- # jobs-discuss (26)
- # lsp (55)
- # observability (3)
- # overtone (1)
- # portal (5)
- # practicalli (1)
- # sql (11)
- # xtdb (8)
hey all, new to datomic. I'm playing around with transactions and queries, and wondered whether I can store a list of references (cardinality many) and keep the order of the items? For example, inserting the following:
{:item/id 1
:item/name "name-1"
:item/children [{:item/id 2 :item/name "name-2"}
{:item/id 3 :item/name "name-3"}]
When querying
(d/q '[:find ?name
:in $ ?id
:where
[?e :item/id ?id]
[?e :item/children ?children]
[?children :item/name ?name]]
(d/db conn)
1)
the children return out of order.
what are the options to keep the order?btw, you can have it sorted by "the date that the child was added as a children"
(sort-by first (d/q '[:find ?inst ?name
:in $ ?id
:where
[?e :item/id ?id]
[?e :item/children ?children ?tx]
[?children :item/name ?name]
[?tx :db/txInstant ?inst]]
(d/db conn)
1))
note that you can also easily sort-by "the that that the child was created"
[?e :item/children ?children]
[?children :item/name ?name ?tx]
[?tx :db/txInstant ?inst]
@U0510KXTU does it change the structure of my schema? Now the children have an intermediate layer when running queries.
Yes, you'll need to unwrap on read and vice versa. I'm guessing you are storing a tree structure. I can vouch for this technique because we use it with diatomic cloud
yes exactly. but what are the benefits of using this technique instead of adding index
to my entity?
Wrapping my entities means changing of my schema structure
That's an option too. We prefer to keep the ordering separate from the domain data. By comparing these options you are at least aware of designs that work
Hey all, how can I execute functions like the built-in in RDBMS (like sort, group by).
I understand that we can execute it in the app (execute sort
on the result set), but is it a best practice? Doesn’t it imply fetching the whole dataset?
How can I execute a query like: find the top 5 most popular posts (`like` column).
> but is it a best practice? In datomic peer/on-prem/Ions, yes. Just use any function to sort and it should perform great, once everything works in-memory etc. In datomic cloud/client, no. IDK the current state of sorting in clinet/cloud libraries.