datascript

Søren Sjørup 2022-12-03T22:36:50.732109Z

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))))

seepel 2022-12-04T23:44:51.564979Z

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
seepel 2022-12-04T23:45:28.477609Z

https://github.com/tonsky/datascript#usage-examples

Søren Sjørup 2022-12-05T15:34:54.935609Z

Thank you very much! @sean888

👍 1