This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-18
Channels
- # announcements (1)
- # babashka (39)
- # babashka-sci-dev (59)
- # beginners (60)
- # calva (14)
- # circleci (1)
- # clj-kondo (16)
- # clj-on-windows (1)
- # clojure (95)
- # clojure-europe (5)
- # clojure-norway (2)
- # clojurescript (34)
- # conjure (2)
- # core-async (55)
- # datomic (4)
- # emacs (54)
- # holy-lambda (5)
- # hyperfiddle (2)
- # interop (4)
- # lsp (8)
- # malli (3)
- # nrepl (4)
- # off-topic (34)
- # polylith (5)
- # reitit (3)
- # releases (2)
- # shadow-cljs (85)
- # specter (2)
- # testing (8)
- # tools-deps (12)
How do I run effect range query on composite tuples? For example, consider the domain of course registrations, modeled with the following entity types:
[{:db/ident :course/id
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :course/campus
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :course/created-at
:db/doc "Timestamp stored as epoch millisec."
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one}
{:db/ident :course/campus+created-at
:db/valueType :db.type/tuple
:db/tupleAttrs [:course/campus :course/created-at]
:db/cardinality :db.cardinality/one}]
Assuming there are lots of campus and courses, how do I effectively list all the courses created after a specific timestamp and is associated with a specific campus?
(The query have to be dynamically generated so raw-index access is not a option)
A
'[:find (pull ?course [...])
:in $ ?campus-id ?timestamp
:where
[(tuple campus-id timestamp) ?tuple]
[?course :course/campus+created-at ?index]
[(>= ?index ?tuple)]
[(untuple ?index) [?campus-id _]]]
B
'[:find (pull ?course [...])
:in $ ?campus-id ?timestamp
:where
[?course :course/campus+created-at ?index]
[(untuple ?index) [?campus-id ?created-at]]
[(>= ?created-at ?timestamp)]]
ref: https://docs.datomic.com/cloud/schema/schema-reference.html#composite-tuples