This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-20
Channels
- # admin-announcements (1)
- # announcements (1)
- # beginners (115)
- # calva (31)
- # cider (25)
- # clj-kondo (47)
- # cljdoc (23)
- # cljs-dev (5)
- # clojars (1)
- # clojure (60)
- # clojure-australia (1)
- # clojure-europe (23)
- # clojure-nl (3)
- # clojure-norway (2)
- # clojure-spec (3)
- # clojure-uk (18)
- # clojurescript (49)
- # community-development (1)
- # cursive (4)
- # datahike (2)
- # datascript (3)
- # datomic (36)
- # deps-new (2)
- # emacs (2)
- # events (9)
- # fulcro (6)
- # graphql (2)
- # gratitude (13)
- # holy-lambda (1)
- # introduce-yourself (10)
- # macro (2)
- # malli (5)
- # meander (9)
- # news-and-articles (5)
- # nextjournal (1)
- # off-topic (32)
- # pathom (17)
- # pedestal (13)
- # polylith (4)
- # protojure (4)
- # reagent (4)
- # sci (27)
- # shadow-cljs (2)
- # show-and-tell (2)
- # specter (3)
- # tools-deps (7)
- # xtdb (16)
Hi Crux team! I know this might sound like micro-optimization but is there a way to get the valid-time from crux/q
?
We need to add something like an :update-at
key to all our models and we wanted to avoid to remember the extra call to crux/entity-tx
We were also thinking of setting :valid-time
and :update-at
at transaction time instead but we are not sure yet about the consequences
Hi @U0C8489U6 there's no built-in way to return this information inside the query, but you can do it like this https://gist.github.com/refset/385d6dcfb66772aa1ec46fc20a49c633 Making valid time first-class in the query language is firmly on the roadmap though 🙂
Ah, I am a big fan of pull
so I am not sure that's going to work here, thanks though
Hmm, yeah, adding a custom parameter hook into the eql would be nice but you can't do that currently
@U899JBRPF would that approach above in the gist have a big impact performance-wise? We ended up using an :updated-at
key in some of the entities but now I am re-considering that approach
Hey @U0C8489U6 the performance should be pretty decent (though not quite as optimal as if it were a native lookup). Perhaps a little bit slower than a simple manual :updated-at
lookup, but it certainly shouldn't present any serious kind of bottleneck.
If using maps as :crux.db/id
values, like :crux.db/id {:foo/id 1}
, is there some way to query for all records that have some such id? Something along these lines:
(let [node sheluchin.server.db.mounts/crux-node]
(sheluchin.server.db.queries/query node
'{:find [foo]
:where [[foo :crux.db/id {:foo/id id}]]}))
I think you will have to specify the full map as entity id - something like:
[foo :crux.db/id {:foo/id 1}]
if you are going for a "list all" without caring about that specific id, the pattern we are using is to have a my-company/type
that would allow us to fetch all the entities for a given keyword
So you just include that field in every document and use it to filter for any given type?
it's also mentioned in the docs but now I cannot find the reference
I wonder if there are any downsides to using metadata like that instead of querying the actual data in some way. Seems like a simple enough approach.
I think such an example is included in the space tutorial. Maybe that's where you saw it. I just wasn't sure if that was a simplified example or a common pattern to use in real applications.
I vaguely remember that benefits outweigh the costs - probably the core team can explain this better but what you also gain is that now your entity type is not "set in stone" - it's just data and can evolve over time