datascript

2023-02-20T19:55:09.653969Z

Should get-else allow a lookup (ie a vector of unique attribute + value) in the eid field? The datomic docs suggest any entity identifier is allowed https://docs.datomic.com/cloud/query/query-data-reference.html#get-else

(d/q
    '[:find ?maybe
      :in $ ?lookup
      :where [(get-else $ ?lookup ::number 0) ?maybe]]
    (d/db-with (d/empty-db {::id {:db/unique :db.unique/identity}})
      [{::id 123}])
    [::id 123])
Results in:
ClassCastException class clojure.lang.PersistentVector cannot be cast to class java.lang.Number...
I can open an issue or possibly attempt a fix

Niki 2023-02-20T20:24:23.920409Z

Does it work if you put vector in the query, not in the parameter?

(d/q
  '[:find ?maybe
    :in $ ?lookup
    :where [(get-else $ [::id ?lookup] ::number 0) ?maybe]]
  (d/db-with (d/empty-db {::id {:db/unique :db.unique/identity}})
    [{::id 123}])
  123)
Seems like a reasonable request either way

Niki 2023-02-20T20:24:37.700369Z

Open an issue, or, better else, PR :)

2023-02-20T20:31:39.282199Z

Same error, and will do!

2023-02-20T20:37:18.035319Z

Issue opened: https://github.com/tonsky/datascript/issues/445 I'll take a stab at a PR soon