Transaction begin;
At the beginning and end of the transaction, the insert, update, delete, and assert statements are wrapped in an atomic execution;
In transactional contexts, transaction submission that supports individual statements is not supported
c.table(tableName).get(jsonObj1).assert(jsonObj2);
Assertion operations in a transaction, assert continues for true, and false rolls back transactions;
JsonObj1: query criteria;
JsonObj2: assertion expression;
Example: In a record of ID equals 1, determine whether age is equal to 52 and name equal to Lisi; if yes, continue; if a condition is not satisfied or the record does not exist, then roll back the transaction;
c.table("posts").get({id: 1}).assert({age:'52',name:'lisi'});
Example: Determines whether the number of rows in a recordset ID equal to 1 is equal to 1, if it continues, and if not, or if the table does not exist, then roll back the transaction;
c.table("posts").get({id: 1}).assert({$rowcount:'1'});
Example: Determines whether table Posts exists, if the table exists, then continues, and if not, then rolls back the transaction;
c.table("posts").assert({$IsExisted:'1'});
Rollback, undo transactions;
This transaction will not be packaged and submitted to the block chain network;
Commit transaction;
All operations during this transaction are packaged and submitted to the block chain network;
Example:
c.beginTran();
c.table("posts").insert({name: 'peera',age: 22},{name: 'peerb',age: 21});
c.table("posts").get({id: 1}).assert({age:22,name:'peera'});
c.table("posts").get({id: 1}).update({age:'52',name:'lisi'});
c.table("comments").delete({id: 1});
c.commit();