Fork me on GitHub
#datomic
<
2016-07-05
>
zentrope00:07:09

When I run a query on d/history, I get a number back for the attribute:

zentrope00:07:19

[277076930200636 102 #uuid "577ae77c-6c62-407f-8123-d48f40dc399f" 13194139534395 true]

zentrope00:07:36

How do I resolve that “102” into the actual :ns/attr?

pesterhazy10:07:59

When using lookup refs in d/q, an invalid input will raise an exception like java.lang.IllegalArgumentException: Cannot resolve key: [:cat.feature/slug "asdf"]

pesterhazy10:07:22

If I want to handle these gracefully (say, return a 404 instead of 500), what's the best way to do that?

pesterhazy10:07:35

1. catch IllegalArgumentException

pesterhazy10:07:59

2. check if the lookup ref check out before (using (->> lookup-ref (d/entity db) :well.known/attr) perhaps)?

robert-stuttaford11:07:28

i'd go with 2., @pesterhazy; presumably your LRs are user input coming in off the web. you'll want to validate those, just like any other user input

rauh12:07:13

@pesterhazy: I'd probably use d/entid instead of entity

pesterhazy12:07:11

@rauh, unfortunately (d/entid (rdb) 12341234) returns 12341234

pesterhazy12:07:27

so it won't discover if an entity-id does not exist

pesterhazy12:07:37

I know I shouldn't be using entity ids anyway, so I guess the real solution would be to stop doing that

marshall12:07:51

@zentrope: Thanks for the deps conflict report. I will look into it today.

conaw16:07:02

Hey all, I’m storing a multigraph in datomic, and I’m interested in the shortest path (or all paths) between 2 or more vertices. I found one example https://hashrocket.com/blog/posts/using-datomic-as-a-graph-database Here, using rules, the author @jgdavey (thanks for the post) was able to get back a path, provided he specified the depth to search. Since that approach is very limited he ended up just working with pure datoms to do the graph search stuff I found a number of papers about implementing recursive algorithms in datalog http://blogs.evergreen.edu/sosw/files/2014/04/Green-Vol5-DBS-017.pdf http://web.cs.ucla.edu/~zaniolo/papers/tplp01.pdf but before trying to convert those into the datomic flavored datalog syntax I know and love, I wanted to see if anyone else has an opinion on this. Has anyone used Loom and Datomic together? Are there some smart patterns for using rules to do recursive querying? Or is @jgdavey’s approach still the best 2 years later?

jgdavey17:07:14

@conaw I ended up using the raw datoms access in part because there was so much less overhead than using the datalog approach. I’d love to see what implementations of those whitepapers would look like (selfishly), but my hunch is that the raw datoms approach is nearly always going to be more performant.

eraserhd22:07:33

OK, so if I `(d/transact conn [[:db.fn/retractEntity :foo]], and on the next line (d/entity (d/db conn) :foo), it’s not nil. What am I missing?

hueyp22:07:46

I think entity always returns a ‘map' with the id you give it even if it does not exist … I feel like I have to do a query to test for existence

hueyp22:07:12

(d/entity (user/db) 123123123123) => {:db/id 123123123123}

hueyp22:07:48

(d/q '[:find ?e
         :in $ ?e
         :where
         [?e]]
       (user/db) 123123123123)
=> #{}

hueyp22:07:51

pull is the same way — always get the id regardless of existance

eraserhd22:07:55

@hueyp: Hi! Hrmm… I thought I tried this, but now I’m not so sure.

marshall22:07:12

@eraserhd: @hueyp is correct. Entities exist independent of whether they have any currently asserted values.

eraserhd22:07:50

Even if I query for it, I get it after a :db.fn/retractEntity

marshall22:07:10

From the Entity documentation: Entities do not "exist" in any particular place; they are merely an associative view of all the datoms about some E at a point in time. If there are no facts currently available about an entity, Database.entity will return an empty entity, having only a :db/id. (http://docs.datomic.com/entities.html)

eraserhd22:07:03

Does :db.fn/retractEntity not retract all values?

marshall22:07:10

Did you get a new database value between issuing the retraction and doing the query?

eraserhd22:07:49

I can definitely query it and show that it still exists.

hueyp22:07:33

hm, dunno … would query for the attributes / values and see if that helps explain? 😜

eraserhd22:07:00

They seem to be all still there.

eraserhd22:07:00

Uh geez. I didn’t deref the transact result.

marshall22:07:48

Exception in there?

eraserhd22:07:25

I think just that it hadn’t completed.

hueyp22:07:30

yah thats all I could think? I think the normal transact blocks regardless of deref

jdubie22:07:50

yup transact blocks regardless of deref. i think it just returns a promise to conform with transact-async interface

eraserhd22:07:29

Yeah, it failed because one of the entities being retracted was an attribute definition.

eraserhd22:07:35

OK, so unblocked. Thanks!

eraserhd22:07:45

@hueyp: Good to see you, too.

marshall22:07:33

Ah. Yeah, can't retract schema. Glad you got it sorted

hueyp22:07:18

@eraserhd: likewise, small world 🙂