Another baby-question: Is there a way for me to 'merge' two variables into one?
For example, ent-784 below has a to-relationship with ent-785, and a from-relationship with ent-786. I'm currently capturing these in two separate variables, and trying to merge them with vector, but that's wrapping the values in a way I don't really want: I'd really like to have ?aliases be the "union" of ?to-a and ?from-a, such that I could use that variable for further joins.
(def rules
'[(alias-from ?from ?to)
[?rel :relationship/from ?from]
[?rel :relationship/type ?type]
[?rel :relationship/to ?to]]
[(alias-of ?subject ?aliases)
(alias-from ?subject ?to-a)
(alias-from ?from-a ?subject)
[(vector ?to-a ?from-a) ?aliases]]])
(d/q
'[:find ?a :in $ % ?subject
:where
(alias-of ?subject ?a)]
(d/db conn) rules 784)
;=> #{[[785 786]]}
I might be using bad terminology here, searching the datomic forums/docs hasn't turned up anything for me; how might I go about this? (or is this "the wrong question", where I should be trying to do something else entirely?)ahhhh, maybe I want to do something with collection-bindings like [?aliases ...], testing
the only way to "expand" the values bound to a variable from multiple sources is with multiple impls of the same rule (or or/or-join, which is syntax sugar for the same thing)
(or-join [?to-a ?from-a ?aliases]
[(identity ?to-a) ?aliases]
[(identity ?from-a) ?aliases])in this case, you can just split your alias-of rule into two
;; from-a
[(alias-of ?subject ?aliases)
(alias-from ?aliases ?subject)]
;; to-a
[(alias-of ?subject ?aliases)
(alias-from ?subject ?aliases)]whoa, didn't know I could have multiple entries of a rule like that, i'd have thought there'd be some kind of collision
no, it is a very fundamental ability
it's how you get both unions and polymorphism
docs: https://docs.datomic.com/query/query-data-reference.html#multiple-rule-heads
I seeee, much appreciated ⭐, i know i've been flooding this channel with kindergarten questions a bit
If i have a user id of 1000 , should that be stored as an int or a long? What is the best practice?
how many users will you have? int is 4 bytes, long is 8
int gives 2 billion user ids
I'll add that by default, like when experimenting in the REPL, an integer will be a java.lang.Long unless explicitly cast.
So if you query (d/q '[:find ?u :in $ :where [?u :user/id 1000]]), you'll get back a big fat (). (see https://clojurians.slack.com/archives/C01RD3AF336/p1771523491680699)
So for my own convenience I've kept all id-like values as longs.
I have WAY less than that. @sludwig.dev That is what i was running into. Getting type missmatch errors. Where queries were returning empty unless id’s were explicitly coerced to longs when loading or at query time.