datascript 2022-12-03

I think I might have found a bug in datascripts handling of many cardinality. This test fails for me:

(let [conn (create-conn)
      _
      (transact conn
                [{:db/ident :x
                  :db/valueType :db.type/long
                  :db/cardinality :db.cardinality/many}])
      {:keys [tempids]}
      (transact conn
                [[:db/add "temp" :x 1]
                 [:db/add "temp" :x 2]])
      temp-id (tempids "temp")]
  (is (= #{[1] [2]}
         (q '[:in $ ?e
              :where [?e :x ?x]
              :find ?x]
            (db conn) temp-id))))

Datascript handles the schema a bit differently from Datomic. You need to pass the schema to create-conn and the format is slightly different. I think you want your example to look like this.

(let [conn (create-conn {:x {:db/cardinality :db.cardinality/many}})
      {:keys [tempids]}
      (transact conn
                [[:db/add "temp" :x 1]
                 [:db/add "temp" :x 2]])
      temp-id (tempids "temp")]
  (is (= #{[1] [2]}
         (q '[:in $ ?e
              :where [?e :x ?x]
              :find ?x]
            (db conn) temp-id))))

🙏 2

Thank you very much! @sean888

👍 1