Fork me on GitHub
Bart Kleijngeld14:05:25

Is there a way to have d/entity include :db/ident in the resulting map?


Uh… no. This was specifically the point in having both :id and :db/ident


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)

Bart Kleijngeld14:05:04

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

Bart Kleijngeld14:05:28

I'm still missing something fundamental I think. When you say "add an :id field", to what should I add it?

Bart Kleijngeld14:05:54

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)

Bart Kleijngeld14:05:39

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)

Bart Kleijngeld14:05:32

So I need to add statements to my triple data for each entity: [:the-entity :id "the-entity-name"]

👍 1
Bart Kleijngeld15:05:24

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"}


Sorry… was writing that while you messaged me, so I didn’t see your context


I have meetings now, so can’t respond for a while

👍 1
Bart Kleijngeld15:05:05

I need to start and make dinner myself, so I'm going to read your reply in more detail later. Thanks!

Bart Kleijngeld16:05:30

I understand now, and it works. Your library and help makes my project so much easier! gratitude

💖 1

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)

👍 1

for now, you’ll need to do that yourself


Sounds good. I know that some of other datalog dbs expose the sorted indexes. Is there something like (example (seek-datoms db :eavt 1) lets you scan an index starting at the datom with entity id >= to 1)