tonsky / datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
Eclipse Public License 1.0
5.49k stars 309 forks source link

`get-else` fails when passed a lookup. #445

Closed jjttjj closed 1 year ago

jjttjj commented 1 year ago

The datomic docs suggest any entity identifier is allowed for the entity argument passed to get-else. However in datascript an exception is thrown when a lookup vector is used.

(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