This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-10
Channels
- # announcements (48)
- # asami (8)
- # babashka (186)
- # beginners (56)
- # calva (42)
- # clerk (84)
- # clj-kondo (75)
- # cljdoc (21)
- # clojure (121)
- # clojure-art (1)
- # clojure-australia (1)
- # clojure-china (1)
- # clojure-conj (2)
- # clojure-europe (10)
- # clojure-filipino (1)
- # clojure-hk (1)
- # clojure-indonesia (1)
- # clojure-japan (1)
- # clojure-korea (1)
- # clojure-my (1)
- # clojure-nl (2)
- # clojure-norway (9)
- # clojure-sg (1)
- # clojure-taiwan (1)
- # clojure-uk (2)
- # clojurescript (11)
- # cursive (30)
- # datalevin (20)
- # datomic (4)
- # fulcro (5)
- # gratitude (1)
- # hyperfiddle (89)
- # introduce-yourself (1)
- # java (5)
- # jobs-discuss (8)
- # lsp (89)
- # malli (57)
- # membrane (16)
- # off-topic (12)
- # pathom (38)
- # releases (5)
- # shadow-cljs (17)
- # tools-deps (18)
- # xtdb (62)
Hello everyone, Would it be possible to mix a Datomic DB and a Datalevin DB in the same (Datomic) query ?
(require '[datomic.api :as d])
(require '[datalevin.core :as dl])
(def dl-conn
(dl/create-conn "/tmp/datalevin/dl_db" {}))
(dl/transact dl-conn [{:user/email ""
:user/email-hash "e2e6d7a977f2ca2b3900e22c68655b30"}])
(d/q '[:find ?fullname .
:in $ $dl ?email
:where
[$dl ?datalevin-id :user/email ?email]
[$dl ?datalevin-id :user/email-hash ?email-hash]
[$ ?datomic-id :user/email-hash ?email-hash]
[$ ?datomic-id :user/fullname ?fullname]
]
(d/db datomic-conn) @datalevin-conn "") ;; => nil
The idea would be to join around the ?email-hash
value and use Datalevin as a mutable store where critical GDPR values can be deleted.
I tried it and got nil
as a result.Instead of using the db position in the where clauses, could you call a nested query on the datalevin db? Something like this (untested)
(d/q '[:find ?fullname .
:in $ $dl ?email
:where
[(datalevin.core/q [:find ?email ?email-hash
:where
[$dl ?datalevin-id :user/email ?email]
[$dl ?datalevin-id :user/email-hash ?email-hash]]
$dl)
[?email ?email-hash]]
[$ ?datomic-id :user/email-hash ?email-hash]
[$ ?datomic-id :user/fullname ?fullname]
]
(d/db datomic-conn) @datalevin-conn "")
I forget off hand how what's required to invoke arbitrary functions like this on datomic, but I know something like this should work if you instead invert things and call datomic from a datalevin query:thinking_face: I don't get exactly what kind of Datomic clause is the following code:
[(datalevin.core/q [:find ?email ?email-hash
:where
[$dl ?datalevin-id :user/email ?email]
[$dl ?datalevin-id :user/email-hash ?email-hash]]
$dl)
[?email ?email-hash]]
From https://docs.datomic.com/on-prem/query/query.html
I can see:
pred-expr = [ [pred fn-arg+] ]
fn-expr = [ [fn fn-arg+] binding]
Is it one of the two?It's surprisingly hard to find documentation of this ability, across datomic/datalevin/datascript
I think in datomic you may need to register the function or something, and it might be different behavior across cloud and on prem
but on datascript at least, and i think datalevin, you can just use any fully qualified symbol within a query
In your code you are using datomic as the query engine, maybe do the reverse? datascript/datalevin can query on any data source that looks like a seq of triples (triple could be a vector or a map), i.e. something like [[1 :a "a"] [2 :b "b"]]
is a valid data source, even [[:a "a"] [:b "b"]]
works. Not sure about datomic.
and as jjttjj said, you can use whatever fully qualified function in the query in datalevin.
I was taking inspiration from this article: https://tgk.github.io/2012/11/creating-datomic-data-sources.html
Is datalevin.core/v
supposed to work on the results of get-range
?
(->> (dl/get-range kvdb jobs-table [:all] :instant :data)
(mapv dl/v))
Is giving me:
IllegalArgumentException No implementation of method: :v of protocol: #'datalevin.lmdb/IKV found for class: clojure.lang.PersistentVector
k
and v
are there for working with IKV
, which is the raw point query result. Range query results are already compatible with Clojure data structures, so you shouldn’t need to use these.
k
and v
is needed if you are writing a predicate, for example, where you need to deal with raw IKV