Fork me on GitHub
#xtdb
<
2023-06-16
>
Viktor Ji00:06:44

Hey! I would like to add a transaction function to my XTDB database to update a specific field on a document. What is the best practice in terms of instantiating the transaction function here? Some naive approaches include instantiating the function prior to each update call I am making (feels very redundant) or directly insert the transaction function into the DB somehow? For context I am interacting with the XTBD via HTTP. Thanks!

hifumi12300:06:22

One thing I've been doing is checking for existence of the tx functions I'll need on app startup. Though I think another thing you can do is run a transaction with [::xt/match eid nil] so that a put is only done when the entity doesn't exist in the database.

thanks2 2
wotbrew09:06:19

1.23.3 has just been released! ๐Ÿš€ Release notes here: https://github.com/xtdb/xtdb/releases/tag/1.23.3 Thanks to all who contributed, raised issues or assisted in this release ๐Ÿ™.

๐ŸŽ‰ 12
๐Ÿš€ 2
๐ŸŽ… 2
nivekuil15:06:02

it looks like the xt2 and xt1 api share namespaces. how does using both in the same project, for e.g. double write migration work?

jarohen16:06:27

hey @U797MAJ8M, it's been a while ๐Ÿ‘‹ we currently have two options: 1. the 1.x migration tool is in two parts: a replicator module for 1.x that streams a replication log out, and an importer module for 2.x that reads the log in. these two are separate JVMs, so namespace clashing isn't an issue in this case 2. if people still need the two versions in one JVM, we can discuss implementing and releasing a springboard version of XT 1.x with xtdb1 namespaces, so that the migration becomes a two-step process - the first a big find/replace to move all existing calls to xtdb1, the second to bring in XT 2.x and start calling the new APIs we'd prefer users use the former if possible, because this cuts down on the chances of the usual dual write issues (writing to one system but not the other)

nivekuil16:06:04

hi ๐Ÿ™‚ I was thinking of dumping some new stuff into xt2 from kafka streams while maintaining all the xt1 stuff in place, just for one specific use case. Operationally I prefer this approach for sure but would love to read more about 1.

Luciano Laratelli20:06:50

is it possible to order-by in a join? I tried this out but no dice:

(q '{:find (pull ?checklist [* {(:task/_checklist-id {:as :checklist/tasks
                                                      :order-by [:task/position :asc]})
                                [*]}])
    :where [[?checklist :checklist/checklist-id]]})
(data shape in ๐Ÿงต)

Luciano Laratelli20:06:07

({:checklist/checklist-id #uuid "8a03e8ed-9f21-4afa-a282-a9619ccb0c2d",
  :checklist/name "test",
  :checklist/owner #uuid "7e356236-62ad-49e1-8986-940e29748e5c",
  :checklist/task-count 2,
  :checklist/status :done,
  :xt/id #uuid "8a03e8ed-9f21-4afa-a282-a9619ccb0c2d",
  :checklist/tasks
  ({:task/owner #uuid "7e356236-62ad-49e1-8986-940e29748e5c",
    :task/name "test2",
    :task/status :incomplete,
    :task/checklist-id #uuid "8a03e8ed-9f21-4afa-a282-a9619ccb0c2d",
    :task/position 1,
    :task/task-id #uuid "062e37ef-c5d6-4f8c-929c-d9906fa3aadb",
    :xt/id #uuid "062e37ef-c5d6-4f8c-929c-d9906fa3aadb"}
   {:task/owner #uuid "7e356236-62ad-49e1-8986-940e29748e5c",
    :task/name "test",
    :task/status :incomplete,
    :task/checklist-id #uuid "8a03e8ed-9f21-4afa-a282-a9619ccb0c2d",
    :task/position 0,
    :task/task-id #uuid "6e96f320-56ba-491e-a634-3736f355d04e",
    :xt/id #uuid "6e96f320-56ba-491e-a634-3736f355d04e"})})

Jacob O'Bryant21:06:02

I don't think it's possible to sort the documents nested inside of a pull, at least not from within the call to q--you could always do it afterward though:

(->> (q ...)
     (map (fn [checklist]
            (update checklist :checklist/tasks
                    (fn [tasks]
                      (sort-by :task/position tasks))))))

Jacob O'Bryant21:06:25

the order-by mentioned in the xtdb docs only works in the top-level, e.g.

(q db
   {:find [(pull task [*]) position]
    :order-by [[position :asc]]
    :where [[task :task/position position]]})

Luciano Laratelli00:06:06

> only works in the top-level TIL, thank you Jacob! ๐Ÿ™‚

๐ŸŽ… 2