This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-05-18
Channels
- # announcements (2)
- # asami (20)
- # aws (4)
- # babashka (35)
- # beginners (47)
- # calva (65)
- # cider (19)
- # clj-kondo (63)
- # clojure (177)
- # clojure-austin (2)
- # clojure-europe (27)
- # clojure-nl (1)
- # clojure-uk (4)
- # clojurescript (13)
- # community-development (5)
- # conjure (5)
- # css (2)
- # data-oriented-programming (9)
- # datalevin (13)
- # datascript (15)
- # datomic (4)
- # devcards (6)
- # duct (4)
- # emacs (8)
- # funcool (1)
- # gratitude (2)
- # helix (3)
- # hyperfiddle (3)
- # introduce-yourself (1)
- # jobs (4)
- # jobs-discuss (26)
- # lambdaisland (2)
- # lsp (20)
- # malli (2)
- # meander (2)
- # mid-cities-meetup (5)
- # missionary (15)
- # music (4)
- # off-topic (37)
- # reagent (3)
- # reitit (2)
- # releases (2)
- # ring (18)
- # shadow-cljs (70)
- # specter (4)
- # sql (20)
- # timbre (3)
- # tools-build (43)
- # tools-deps (11)
- # vim (11)
- # xtdb (61)
Is there a way to have d/entity
include :db/ident
in the resulting map?
if you want an id in the entity object that’s returned, then use :id
. Otherwise, use :db/ident
(which is supposed to be an internal property that is not visible via the entity interface)
Ah alright good to know. I'm currently loading my triples using :tx-triples
, which seems to automatically use :db/ident
. Can I customize that?
If there is no id, then it creates one that refers back to the entity reflexively. But just add an :id
field and you’ll get that instead
Well… not “instead”. I still create a :db/ident
property on the entity, since I’m trying for consistency across all entity objects. But you can use the :id
instead of the :db/ident
I'm still missing something fundamental I think. When you say "add an :id
field", to what should I add it?
To add a little more context: I want to recursively fetch an entity, but at each level of depth my I need to add a name field (for my goal) that depends on the identifier (originally the subject of the triple)
Ah I'm starting to get it a bit better. You mean in the triple data I guess, as in the example in the wiki in 3. Loading Data (Triples section)
So I need to add statements to my triple data for each entity: [:the-entity :id "the-entity-name"]
I'm going to try, thanks
well, if you see this EDN (which could have come from JSON):
[{:data "one"}
{:data "two"}
{:data "three"}]
Then what gets inserted is the equivalent to:
[{:db/ident "node-1", :data "one"}
{:db/ident "node-2", :data "two"}
{:db/ident "node-3", :data "three"}]
You will need to do queries to find which identifiers it used, but once you have them you can ask for things like:
(entity db "node-2")
Returning: {:data "two"}
Alternatively, you can set the idents:
[{:db/ident 1, :data "one"}
{:db/ident 2, :data "two"}
{:db/ident 3, :data "three"}]
And this will be inserted. Now you already know the IDs, and can say:
(entity db 2)
Returning: {:data "two"}
But say you like having IDs. So now you can insert:
[{:id 101, :data "one"}
{:id 102, :data "two"}
{:id 103, :data "three"}]
This will still create identifiers for :db/ident
(because it always ensures that a :db/ident
exists), so you’ll get the equivalent to an insertion of:
[{:db/ident "node-42", :id 101, :data "one"}
{:db/ident "node-43", :id 102, :data "two"}
{:db/ident "node-44", :id 103, :data "three"}]
If you query the db for the idents, then you can still use these:
(entity db "node-43")
Returning: {:id 102, :data "two"}
Or you can use the :id
that you set (you set it, because you wanted to use it for exactly this purpose):
(entity db 102)
Returning: {:id 102, :data "two"}
I need to start and make dinner myself, so I'm going to read your reply in more detail later. Thanks!
I understand now, and it works. Your library and help makes my project so much easier!
Is there a way to query entities ordered by some property (eg. grab the 50 most recent entities sorted in descending order by :my.entity/entity-instant
)?
No. That’s a TODO feature.
The implementation will include the property in some column number n
, use (sort-by #(nth % n) results)
, and then do the required projection (as specified in the :find
clause)
Sounds good. I know that some of other datalog dbs expose the sorted indexes. Is there something like https://docs.datomic.com/on-prem/clojure/index.html#datomic.api/seek-datoms? (example (seek-datoms db :eavt 1)
lets you scan an index starting at the datom with entity id >=
to 1
)