This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-02
Channels
- # announcements (1)
- # babashka (4)
- # beginners (39)
- # calva (36)
- # cherry (11)
- # cider (23)
- # clj-on-windows (3)
- # clojure (105)
- # clojure-brasil (1)
- # clojure-chicago (3)
- # clojure-conj (8)
- # clojure-denver (4)
- # clojure-europe (18)
- # clojure-germany (5)
- # clojure-hungary (13)
- # clojure-nl (1)
- # clojure-norway (31)
- # clojure-sweden (9)
- # clojure-uk (2)
- # clojurescript (22)
- # core-async (4)
- # cursive (8)
- # data-science (25)
- # datomic (14)
- # devops (1)
- # emacs (9)
- # events (5)
- # holy-lambda (32)
- # hyperfiddle (26)
- # introduce-yourself (2)
- # kaocha (1)
- # leiningen (11)
- # lsp (17)
- # malli (8)
- # off-topic (84)
- # pedestal (4)
- # polylith (2)
- # re-frame (17)
- # reitit (1)
- # releases (1)
- # remote-jobs (1)
- # shadow-cljs (8)
- # sql (4)
- # tools-deps (8)
- # transit (5)
- # vim (1)
- # vscode (1)
- # xtdb (45)
with morse being open sourced (w/ replicant) I guess that would be the best way to explore an XTDB even remotely, anyone tried it yet?
I've not, I am certainly curious though! I guess your https://github.com/tatut/xtdb-inspector module is more "operational" but are there things that morse could make simpler?
Well, inspector really is there to get something for the ops people. Sometimes you just need a way into looking at the db and you dont have a custom UI for it. I guess in xtdb2 you can just use any postgres client?
> I guess in xtdb2 you can just use any postgres client? maybe - hopefully once we've sorted out the INFORMATION_SCHEMA story, at least
Hi, I have a question about datalog / xtdb : I'm trying to understand how this could be done more efficiently.
I have a "blogpost" that has multiple :post/tag
that have as values some ids of tags. I'd like to query the blogpost and get the names in the result and not the ids.
My insert :
(xt/submit-tx xtdb-node [[::xt/put
{:xt/id :another
:tag/name "tata"}]])
(xt/submit-tx xtdb-node [[::xt/put
{:xt/id :test-tag
:tag/name "toto"}]])
(xt/submit-tx xtdb-node [[::xt/put
{:xt/id :test-post
:post/title "title"
:post/content "content"
:post/tags [(first (first (xt/q (xt/db xtdb-node)
'{:find [id]
:where [[id :tag/name "toto"]]})))
(first (first (xt/q (xt/db xtdb-node)
'{:find [id]
:where [[id :tag/name "tata"]]})))
]}]])
My query:
(xt/q (xt/db xtdb-node)
'{:find [?title ?content ?tag-name]
:where
[[?post :post/title ?title]
[?post :post/content ?content]
[?post :post/tags ?tag-entity]
[?tag-entity :tag/name ?tag-name]
[(= :test-post ?post)]
]})
This gives the following result :
#{["title" "content" "toto"] ["title" "content" "tata"]}
This is what I want, but this would be nice if I could do like "coalescing" into a collection, I'm not sure if that's possible.Okay, seems I found what I want using pull! I replaced the tags by a set of tags for the blogposts. I can query them that way :
(xt/q (xt/db xtdb-node)
'{:find [(pull ?post [* {:post/tags [:tag/name :xt/id]}])]
:where
[[?post :post/title ?title]
[?post :post/content ?content]
[?post :post/tags ?tag-entity]
[?tag-entity :tag/name ?tag-name]
[(= :test-post ?post)]
]})
And it gives the following
#{[{:post/title "title", :post/content "content", :post/tags [{:tag/name "toto", :xt/id :test-tag} {:tag/name "tata", :xt/id :another}], :xt/id :test-post}]}
Yep pull syntax is what I would do, also very small thing but clojure has ffirst
instead of (first (first ...
Hi, is there a way to put a record with datetime using json (equivalent to #inst
if I were to use edn)? The following will treat “1985-01-01” as string, which makes it hard to do any date comparison in a query (if there is a good way, I’m all ears). Thank you!
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"tx-ops": [["put", {"xt/id": "user1",
"birthday": "1985-01-01"
}]]}' \
"$xtdb_url/_xtdb/submit-tx"
Hey @U054KQT2081 XTDB doesn't do anything clever to interpret/coerce JSON document contents as anything other than the https://www.json.org/json-en.html JSON types - so unfortunately there's no easy answer here. However you should be able to submit documents containing well-formed UTC ISO 8601 datetime strings and rely on the lexicographical sorting
got it. Thank you!
Out of interest, have you already tried using https://github.com/go-edn/edn ?
I’m trying to write a query with a combo of inclusions and exclusions and having trouble trying to work out how to format the :in
and how to pass the arguments to the query. 🧵
I have a where clause that contains these two terms:
'[[?x :tags tags]
(not [?x :tags exclude-tags])]
Then figured I should write my :in
as:
'[[tags ...] [exclude-tags ...]]
And then try to call with:
(xt/q
(xt/db node)
query
[["in-tag1" "in-tag2"] ["not-tag1" "not-tag2"]])
I’ve tried a lot of variations, but can’t figure out how to pass the two vectors successfully. If it comes to it, I can manually build the query instead, but it feels like I should be able to pull this off without that extra work.
(I think I’m going to be embarrassed now. I think I’ve got it).
Well, it’s not blowing up anymore, but I’m getting bad results…I’m trying to and
the two disparate terms together but that’s not helping. (The fix for the initial problem, of course, was just to extract the two vectors and pass as separate args).
Even after moving to manually adding my not
clause, I’m getting results that include the tags that should be excluded. Can I not execute a “with these but not those” query at all, or is there more likely something just wrong with my structure still?
Hey @U01GXCWSRMW 🙂 I'm not sure I'm following entirely - if you can share a slightly more completely example it will probably shed light
I’ll have to write a short example of what I want. Not sure I’ll get to it until tomorrow.
based on your description it sounds like you want your :in
bindings to be scalars (i.e. raw clojure sets) not collections/relations
then it might be:
'[[?x :tags tag]
[(contains? tags tag)]
(not [(contains? exclude-tags tag)])]
Something like that, yeah.
Except, I want it on the same field. Two sets of params against a single field. Something like… “Find me all the articles with a content tag of [‘intro’ ‘intermediate’] that do not have a content tag of [‘java’ ‘kotlin’].”
In practice, it’d be more like: tagged-with: ‘intro’ not-tagged-with: ‘java’, ‘kotlin’, ‘golang’, ‘python’
I can manage it manually (finally!) where I do an in clause for my vector (e.g. “intro”) and then conj a bunch of not
clauses for each of my exclusions. It’s not the ugliest code, but seems like I’m solving a problem with a hammer that probably has a screwdriver that would fit. 🙂
I’ll try to get a good sample together tomorrow.
Example gist here - https://gist.github.com/coyotesqrl/f5d72c7b940b9a02e0fbc667b29d8909
Hi, is https://www.xtdb.com/blog/xtdb-transaction-functions.html#_transaction_functions the recommended way to update a record in xtdb? and can transaction function be created via http client? Just copying the code didn’t work for me. Thanks!
curl -X POST \
-H "Content-Type: application/edn" \
-H "Accept: application/json" \
-d "{:tx-ops [[:xtdb.api/put {:xt/id :increment-age
:xt/fn '(fn [ctx eid]
(let [db (xtdb.api/db ctx)
entity (xtdb.api/entity db eid)]
[[:xtdb.api/put (update entity :age inc)]]))}
]]}" \
"$xtdb_url/_xtdb/submit-tx"
Hey @U054KQT2081 transaction functions are generally the easiest way to update a record, yes, because they have the simplest consistency guarantees (whereas xtdb.api/match
requires backoff & retry) and give you an opportunity to perform schema validations, integrity checks etc.
> and can transaction function be created via http client?
yes it should be no problem - the issue you're seeing may be because Accept: application/json
needs to be application/edn
also

{:error "Malformed \"application/edn\" request."}
ah, yes that would be expected 🙂 the container log might show more info about how the request was malformed (or if it doesn't currently, then it certainly could be made to do so - or indeed we could pass more info back via the HTTP response)
@U899JBRPF I started the server locally with java -jar xtdb.jar -f xtdb.edn
. I didn’t see any err/log in std. where else can I find logs?
you would probably need to configure a logback.xml under a resources
dir like https://github.com/xtdb/xtdb/blob/master/bench/resources/logback.xml + with <logger name="xtdb" level="DEBUG" />
thanks for the pointers! I see logs for other queries/tx, which will be useful for the future. no logs for the ones with malformed requests. but just removing the single quote in front of (fn [ctx eid]
got me around the error!
now calling the function is giving me Transaction aborted:
lmk if you have a hunch of what else could be wrong. otherwise, I will play around more later.
thanks again!
some of the dev-time UX is definitely easier when you're working in-process with a proper JVM stack trace but Transaction aborted:
is generally a little tricky due to the async nature
this may be useful to you https://github.com/xtdb/xtdb/pull/1902#issuecomment-1489835090

hmm so '
is needed? but that doesn’t seem to be valid edn syntax