datahike

itaied 2025-12-14T12:20:01.320909Z

hey all what are the constraints and limitations on schema-on-read ? i have tried filtering the data without specifying the schema and it doesn't work, so i wonder what about history and other features that are limited this way

(def cfg {:store {:store :mem :id "schema-on-read"}
            :schema-flexibility :read})

  (def schema [{:db/ident :id
                :db/valueType :db.type/string
                :db/cardinality :db.cardinality/one
                :db/unique :db.unique/identity}
               {:db/ident :amount
                :db/valueType :db.type/float
                :db/cardinality :db.cardinality/one}
               {:db/ident :my-ref
                :db/valueType :db.type/ref
                :db/cardinality :db.cardinality/one
                :db/isComponent true}])

  (d/create-database cfg)

  (def conn (d/connect cfg))

  (d/transact conn {:tx-data schema})
  (d/transact conn {:tx-data [{:id "my-map"
                               :amount 0
                               :my-ref {:input {:value 0
                                                :meta "data"}
                                        :some-vec ["some" "value"]}}]})

  (d/q '[:find ?e (pull ?ref [*])
         :where
         [?e :my-ref ?ref]
         [?e :amount ?amount]
         [(> ?amount 0)]]
       @conn) ; => []

  (d/q '[:find ?e (pull ?ref [*])
         :where
         [?e :my-ref ?ref]
         [?ref :input ?i]
         [(> (get ?i :value) 0)]]
       @conn) ; => [[4 {:db/id 5, :input {:value 0, :meta "data"}, :some-vec ["some" "value"]}]]

whilo 2025-12-18T20:11:35.282499Z

hey @itai. does this work with schema on write? nested s-expressions in predicates do not work in datomic and datahike, you need to bind them first, i think the problem is (> (get ?i :value) 0); what happens if you bind (get ?i :value) to a logic var first and then evaluate the predicate?

whilo 2025-12-18T20:12:10.321249Z

maybe this should still fail and not return anything, not sure what datomic does in this case

itaied 2025-12-19T19:05:12.841689Z

yes it did fail also i'm not comparing it to datomic, just trying to wrap my head around schema-on-read and its caveats