You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just started using surrealdb and surrealdb.js with deno for a backend service. I have one instance of Surreal that is being passed around.
Yesterday I used transactions for the first time. No issues so far. However, I asked myself the question how multiple concurrent transactions are supported by surrealdb.js. From what I've read and what I understood there's only one WebSocket connection that is used to handle all the communication with surrealdb.
(A1) BEGIN TRANSACTION;
(A2) CREATE account:one SET balance = 135,605.16;
(A3) CREATE account:two SET balance = 91,031.31;
(A4) UPDATE account:one SET balance += 300.00;
(A5) UPDATE account:two SET balance -= 300.00;
(A6) COMMIT TRANSACTION;
And add to that a second transaction:
(B1) BEGIN TRANSACTION;
(B2) CREATE account:three SET balance = 99,000.00;
(B3) CREATE account:four SET balance = 666,666.66;
(B4) UPDATE account:three SET balance += 200.00;
(B5) UPDATE account:four SET balance -= 900.00;
(B6) COMMIT TRANSACTION;
Let's say I start with A1 and execute until A3. New work gets introduced to the backend service and we start with B1 to B3 in a different context but still the same process. Then we continue with A and go from A4 to A6 and end the transaction. From my understanding that would mean that also B2 and B3 get committed which is certainly not intended by me as a programmer and as soon as B4 to B6 executes we end up with a weird state(?).
I am a little confused about what to expect here and what the actual behavior is. Any help on getting a proper understanding regarding transactions in the context of surrealdb.js would be highly appreciated.
When searching this repo for transactions I only found this (closed) PR: #56
There @tobiemh mentioned something about "atomic transactions" which I actually do not understand.
Kind regards
Jens
The text was updated successfully, but these errors were encountered:
transactions are built to ensure that all queries are succesfully executed (committing a transaction), or to view how a change would affect the database (cancelling a transaction). You can only execute these transactions in go, not in separate queries.
Does that help? Let me know if anything is unclear!
-- Micha
Hi all!
I just started using surrealdb and surrealdb.js with deno for a backend service. I have one instance of Surreal that is being passed around.
Yesterday I used transactions for the first time. No issues so far. However, I asked myself the question how multiple concurrent transactions are supported by surrealdb.js. From what I've read and what I understood there's only one WebSocket connection that is used to handle all the communication with surrealdb.
Let's have a look at the (shortened) example from the official surrealdb docs:
And add to that a second transaction:
Let's say I start with A1 and execute until A3. New work gets introduced to the backend service and we start with B1 to B3 in a different context but still the same process. Then we continue with A and go from A4 to A6 and end the transaction. From my understanding that would mean that also B2 and B3 get committed which is certainly not intended by me as a programmer and as soon as B4 to B6 executes we end up with a weird state(?).
I am a little confused about what to expect here and what the actual behavior is. Any help on getting a proper understanding regarding transactions in the context of surrealdb.js would be highly appreciated.
When searching this repo for transactions I only found this (closed) PR:
#56
There @tobiemh mentioned something about "atomic transactions" which I actually do not understand.
Kind regards
Jens
The text was updated successfully, but these errors were encountered: