This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-02-01
Channels
- # announcements (14)
- # architecture (30)
- # aws (34)
- # babashka (18)
- # beginners (114)
- # biff (5)
- # calva (128)
- # clerk (155)
- # clj-kondo (60)
- # clojure (82)
- # clojure-dev (25)
- # clojure-europe (20)
- # clojure-nl (1)
- # clojure-norway (17)
- # clojure-spec (13)
- # clojure-uk (3)
- # community-development (4)
- # core-logic (4)
- # cursive (5)
- # datomic (21)
- # deps-new (13)
- # emacs (5)
- # funcool (5)
- # graphql (3)
- # hyperfiddle (1)
- # introduce-yourself (1)
- # jobs (2)
- # kaocha (1)
- # london-clojurians (1)
- # lsp (13)
- # malli (16)
- # off-topic (6)
- # other-languages (1)
- # pathom (18)
- # re-frame (23)
- # releases (1)
- # remote-jobs (2)
- # tools-build (1)
- # tools-deps (12)
- # vscode (1)
- # xtdb (27)
How can I get column name and column value from xtdb.
#{[:commodity/CH4 "Methane" :molecule/gas]}
I want to get #{[{:id :commondity/Ch4, :name "Methane" .. }]} like sql from db(mysql) and return the kv collection in clojure.jdbc(def node (xt/start-node {}))
(xt/submit-tx
node
[[::xt/put
{:xt/id :commodity/Pu
:common-name "Plutonium"
:type :element/metal
:density 19.816
:radioactive true}]
[::xt/put
{:xt/id :commondity/N
:common-name "Nitrogen"
:type :element/gas
:density 1.2506
:radioactive false}]
[::xt/put
{:xt/id :commodity/CH4
:common-name "Methane"
:type :molecule/gas
:density 0.717
:radioactive false}]])
(xt/q (xt/db node) '{:find [name]
:where [
[_ :common-name name]
]})
;; => #{["Methane"] ["Plutonium"] ["Nitrogen"]}
how can I get like this
#{[{:id :commodity/Pu :name "Methane" }] [ {:id :commodity/Pu :name "Plutonium" } ] [ {:id :commodity/Pu :name "Nitrogen" }]}
return the all line data like from mysql(->> (xt/q (xt/db node)
'{:find [(pull e [:xt/id :common-name])]
:where [[e :common-name name]]
})
(map first)
(map #(clojure.set/rename-keys % {:xt/id :id, :common-name :name})))
Or
(xt/q (xt/db node)
'{:find [id name]
:keys [id name]
:where [[e :common-name name]
[e :xt/id id]]
})
https://docs.xtdb.com/language-reference/1.23.0/datalog-queries/#return-mapsI should perhaps add you that you can use regular Clojure functions in your clauses to do things like this if really needed:
[(hash-map :foo 1 :bar 2) ?map]
;; with just 'query':
(xt/q
(xt/db node)
'{:find [?uid ?name ?profession]
:where [[?user :user/id ?uid]
[?user :user/name ?name]
[?user :user/profession ?profession]]})
#{[1 "Ivan" :doctor] [2 "Sergei" :lawyer], [3 "Petr" :doctor]}
How can I understand content in :where , is it a condition query? but It's not like SQL where:
select uid,name,profession from node where uid=? or etc...
What's mean by :where above codeThese particular :where clauses have no conditions other than an implied existence predicate, so the effect is only unification and projection. In other words "pattern matching" for only relevant entities that hold all the attributes simultaneously (with potentially many combinations of values)
The unification of ?user here is behaving more like a self join in SQL, but I wouldn't recommend attempting to reason about Datalog in terms of SQL operations too much when trying to learn Datalog
Yeah. In SQL you have tables, that define a scope. You can query all rows in a table, even without knowing what columns exist. Multiple tables might have the same columns you are interested in, or be even identical, but you cannot query for the columns without knowing the table(s). In datalog you query "columns first", in a way. That is, you know at least one attribute you are interested in, and then can get all objects/documents/"rows" that have that, even if they otherwise are different. Database is not the layer that limits the schema, unless you would consider transactions functions to be that (but whenever a client chooses to insert data using a transaction function, it might as well use any other schema mechanism and a plain put).
ok, thanks, maybe I need to read the documentation carefully and understand the usage scenarios of xtdb
Perhaps I misread, but there certainly are scenarios where XTDB is especially useful, but I wouldn't think that you need to have any special needs to gain a lot of benefit compared to SQL, or especially compared to "no-SQL" databases
If you feel uncertain about how you can even find the data you want, when anything could be in the DB, I certainly sympathize
In a way, xt/attribute-stats
might help there. It lets you see what kind of things you could be querying for. And of course you can always query for documents that have :xt/id, i.e. everything
In actual deployed code, the queries would be limited anyway. Meaning that there's no practical difference between a SQL based system inserting and querying rows in a table, and a XTDB/datalog based system putting documents, and then querying the attributes it writes
Thanks. • I have never known about bitemporal database. so I don't know what kind of scenarios to use it in. Because I only have a background in rdbms usage
If you don't have a use for it, it won't get into your way. It lets you answer questions of type "Why did the system show in January that 2022 yearly report was A, but now it's showing it's B"
In SQL, you could perhaps fix that with thinking ahead, and adding a "data_added" column in addition to the actual date column. But handling all cases becomes a hassle
Thank you for a very entertaining meetup session yesterday @mail992/@seiib3/@kevin842/@malcolmsparks/Ezra (and sorry again for the technical trouble @tomi.hukkalainen_slac!) Here's the replay for anyone interested: https://discuss.xtdb.com/t/video-virtual-meetup-1-recording-modelling-and-tradeoffs-discussion/133 - and https://discuss.xtdb.com/t/ann-virtual-meetups-in-2023/129 about registering for the session next week 🙏
Hey XTDB folks! Is there any recommendation for storing a large (XML) payload in XTDB? Do I need extra compression or nippy will take care of it for me? I don't need to query it, it is basically just a blob to hydrate and store as is.
Hey @U0C8489U6 I hope all is well 🙂 I just posted your question onto Discuss and answered it there https://discuss.xtdb.com/t/will-large-xml-blobs-get-compressed/135 Funnily enough it also got discussed during the meetup lightly (though not XML specifically)!