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
It would be awesome to have transaction support for the js sdk. It would make error handling in js way more easier and would require less custom handling on errors.
A good usecase would be for creating 2 table entries with db.create and relating them using db.relate, if any of these operation fail, i want all of the changes to not be applied and the db to be in the same state as before.
Describe the solution
Maybe something similar to how sequelize does it:
// option to create a transactionconsttransaction=awaitdb.transaction();try{// possibility to add the transaction to db methodsawaitdb.create(user,{name: 'testUser'},{ transaction });// supported for every available db method (create, query, insert, relate, etc)awaitdb.query('UPDATE ...',{ transaction })// try to apply the transactionawaittransaction.commit();}catch{// on error just rollbackawaittransaction.rollback();}
Alternative methods
IIRC the only possible way to do transactions from js is using it directly inside db.query like this
db.query(` BEGIN TRANSACTION; CREATE account:one SET balance = 135605.16; CREATE account:two SET balance = 91031.31; UPDATE account:one SET balance += 300.00; UPDATE account:two SET balance -= 300.00; COMMIT TRANSACTION;`);
While this works in many cases it would still be awesome do be able to it with the actualy sdk methods.
So far the ive only recreated firestores client side transactions via read read read write write write, to build a single RPC transaction that aborts of the doc versions have changed since read.
But it would be so nice to have read write read write read write
Is your feature request related to a problem?
It would be awesome to have transaction support for the js sdk. It would make error handling in js way more easier and would require less custom handling on errors.
A good usecase would be for creating 2 table entries with
db.create
and relating them usingdb.relate
, if any of these operation fail, i want all of the changes to not be applied and the db to be in the same state as before.Describe the solution
Maybe something similar to how sequelize does it:
Alternative methods
IIRC the only possible way to do transactions from js is using it directly inside
db.query
like thisWhile this works in many cases it would still be awesome do be able to it with the actualy sdk methods.
SurrealDB version
surreal 2.1.1 for linux on x86_64
JavaScript SDK version
1.1.0
Contact Details
[email protected]
Is there an existing issue for this?
Code of Conduct
The text was updated successfully, but these errors were encountered: