Fork me on GitHub
#datomic
<
2022-08-03
>
Mateusz Mazurczak22:08:04

I want to filter the result by the fact if the key do not exist or it's value (date) is lower then the provided arg. So in pseudo code it would look like this:

[:find ?fizz 
 :in $ ?my-date
 :where 
  [?fizz :fizz/buzz ?buzz]
  (or (missing? $ ?fizz :fizz/date)
      [(< ?now-date [?fizz :fizz/date])])]
Is that possible in the query?

pppaul22:08:46

rules act like logical ors

pppaul22:08:11

or statement and join-or are a bit funky in how they work, and i haven't been very successful in using them

pppaul22:08:31

hmm, i can't seem to use missing? with fake data

pppaul23:08:12

i was trying to do some tests without making a DB, but i get errors with missing?

pppaul23:08:43

you can combine rules to form ORs i think that is a good place to start.

Byron Clark04:08:42

I think you want something like this:

[:find ?fizz 
 :in $ ?my-date
 :where 
  [?fizz :fizz/buzz ?buzz]
  (or-join [?fizz]
    [(missing? $ ?fizz :fizz/date)]
    [(< ?my-date [?fizz :fizz/date])])]

Mateusz Mazurczak09:08:37

@U0394DH0S3W Yeah that's what I meant, but the case is that this code do not work in datomic as this line gives me message:

[(< ?my-date [?fizz :fizz/date])]
Unable to resolve symbol: ?fizz in this context

Mateusz Mazurczak09:08:08

While if I remove this one line it all works

pppaul14:08:12

i'm not sure [?fizz :fizz/date] is valid. does anyone have examples of this syntax being used in queries?

Byron Clark14:08:33

[?fizz :fizz/date] is valid in a where, but I don’t think it does what you want. Sorry I didn’t pay too much attention to that when adding the or-join. [?fizz :fizz/date] unifies ?fizz to entities that have a :fizz/date attribute but it doesn’t extract the value of the attribute. I think this is what you want:

[:find ?fizz 
 :in $ ?my-date
 :where 
  [?fizz :fizz/buzz ?buzz]
  (or-join [?fizz]
    [(missing? $ ?fizz :fizz/date)]
    (and [?fizz :fizz/date ?fizz-date]
         [(< ?my-date ?fizz-date))])]