๐ Doesnโt datalevin support transacting nested maps and creating entities from refs that have db/isComponent? true or am I holding it wrong? Example in ๐งต
Sure, please do
Datomic example first, same schema and data doesnโt work as I expected in datalevin:
(require '[datomic.api :as d])
(def db-uri "datomic:")
(d/create-database db-uri)
(def conn (d/connect db-uri))
(def schema [{:db/ident :question/answers
:db/cardinality :db.cardinality/many
:db/isComponent true
:db/valueType :db.type/ref}
{:db/ident :question/key
:db/cardinality :db.cardinality/one
:db/valueType :db.type/keyword}
{:db/ident :question/title
:db/cardinality :db.cardinality/one
:db/valueType :db.type/string
:db/fulltext true}
{:db/ident :answer/value
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :answer/category
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}])
@(d/transact conn schema)
(d/q '[:find ?e
:where
[?e :db/ident :answer/category]]
(d/db conn))
(def data [{:question/key :hmsacld
:question/answers [{:answer/value "1"
:answer/category "strongly agree"}
{:answer/value "2"
:answer/category "agree"}
{:answer/value "3"
:answer/category "disagree"}
{:answer/value "4"
:answer/category "strongly disagree"}]
:question/title "Datalog is awesome"}])
@(d/transact conn data)
(d/q '[:find ?t ?av ?ac
:where
[?e :question/key :hmsacld]
[?e :question/title ?t]
[?e :question/answers ?a]
[?a :answer/value ?av]
[?a :answer/category ?ac]]
(d/db conn))
;;=> #{["Datalog is awesome" "1" "strongly agree"] ["Datalog is awesome" "3" "disagree"] ["Datalog is awesome" "2" "agree"] ["Datalog is awesome" "4" "strongly disagree"]}
(require '[datalevin.core :as dl])
(def dl-db-uri "/tmp/datalevin/hello")
(def dl-conn (dl/get-conn dl-db-uri))
@(dl/transact dl-conn schema)
@(dl/transact dl-conn data)
;; But it was transacted successfully
(dl/q '[:find ?t ?av ?ac
:where
[?e :question/key :hmsacld]
[?e :question/title ?t]
[?e :question/answers ?a]
[?a :answer/value ?av]
[?a :answer/category ?ac]]
(dl/db dl-conn))
;;=> #{}
;; But something was transacted successfully
(dl/q '[:find ?t
:where
[?e :question/key :hmsacld]
[?e :question/title ?t]
;; [?e :question/answers ?a]
;; [?a :answer/value ?av]
;; [?a :answer/category ?ac]
]
(dl/db dl-conn))
;;=> #{["Datalog is awesome"]}
But Iโm pretty sure itโs supported because simongray wrote about it in another slack channel.Absolutely no urgency here, just getting to know a bit of Datalog. And great job creating datalevin, thank you ๐
Likely a query bug, could you file an issue? I will take a look
Done, thanks!
A few things: Datalevin's schema is just a map of maps. There's also no need to transact them.
So Datomic's handling of schema is very different from Datalevin.
Also, you query contains a clause that matches nothing. :question/key doesn't exist in the data.
In any case, it works fine after fixing these.
Oh thanks a lot for the education! The missing :question/key data happened when creating the issue, it was present in the initial test code, sorry for that!
Works now, thanks so much for your help!
I did try it before with the schema as a map of maps. But I tried to transact that schema, which errored because I was trying to transact a map. Then I just refactored it to a datomic like schema sequence and transacted that one. Would you be open to a very small PR mentioning this small difference in the Readme (last 4 lines):
;; Define an optional schema.
;; Note that pre-defined schema is optional, as Datalevin does schema-on-write.
;; However, attributes requiring special handling need to be defined in schema,
;; e.g. many cardinality, uniqueness constraint, reference type, and so on.
;; Differences to Datomic:
;; - The schema must be a map of maps, not a vector of maps.
;; - It is not `transact`ed into the db but passed on when acquiring connections.
;; - use `update-schema` to update the schema of an open connection to a database.
Or feel free to just use it if you think itโs useful or ignore if itโs too noob.Merged.
I keep getting the below error. Is there any reason why load and sync aren't excluded with refer-clojure?
WARNING: sync already refers to: #'clojure.core/sync in namespace: datalevin.core, being replaced by: #'datalevin.core/sync
WARNING: load already refers to: #'clojure.core/load in namespace: datalevin.core, being replaced by: #'datalevin.core/load
It's not a big deal; I'm just wondering. tyThanks. I've upgraded. I was previously on v0.9.11
They are excluded.
maybe you are on an older version?