Fork me on GitHub
#datascript
<
2017-04-25
>
dmitriid09:04:20

BTW. It worked!

dmitriid09:04:00

However, our API is so bad, itโ€™s easier to do lookups via regular :finds ๐Ÿ™‚

bbss12:04:47

I think I don't understand how or is supposed to work, I've tried many combinations found in the tests but can't get anything working. (tests: https://github.com/tonsky/datascript/blob/master/test/datascript/test/query_or.cljc)

bbss12:04:50

The result of that query is an error #object[Error Error: Cannot compare :something to [?fail-or-success :item/succ ?entity]]

misha12:04:42

@bbss or is not released yet. "or" tests test api_v3, not an actual "shipped" one

misha12:04:53

for or use rules

bbss12:04:19

Hmm, yeah I was afraid of that. Time to figure out rules. Thanks @misha

misha12:04:24

@bbss

(let [conn (ds/create-conn
              {:items     {:db/valueType :db.type/ref :db/cardinality :db.cardinality/many}
               :item/succ {:db/valueType :db.type/ref :db/cardinality :db.cardinality/one}
               :item/fail {:db/valueType :db.type/ref :db/cardinality :db.cardinality/one}})
      rules '[[(fail-or-success ?e ?i) [?e :item/succ ?i]]
              [(fail-or-success ?e ?i) [?e :item/fail ?i]]]]

  (ds/transact! conn [{:db/id -1 :items [-2 -3 -4]}
                      {:db/id -2 :something :successful}
                      {:db/id -3 :something :in-progress}
                      {:db/id -4 :something :failing}
                      {:db/id -5 :item/succ -2}
                      {:db/id -6 :item/fail -4}])

  (ds/q '[:find (pull ?items [*]) (pull ?e [*])
          :in $ %
          :where
          (fail-or-success ?e ?i)
          [?items :items ?i]]
     @conn rules))
=>
([{:db/id 1, :items [{:db/id 2} {:db/id 3} {:db/id 4}]}
  {:db/id 5, :item/succ {:db/id 2}}]
 [{:db/id 1, :items [{:db/id 2} {:db/id 3} {:db/id 4}]}
  {:db/id 6, :item/fail {:db/id 4}}])

bbss12:04:20

@misha wow! thanks! that looks great even ๐Ÿ™‚

bbss14:04:52

really weird syntax though, it looks like a function call, but doesn't really have a formal looking definition