Transactions¶
ArcaneDB supports both implicit and explicit transaction management.
Implicit Transactions¶
Every data-modifying statement automatically participates in an implicit transaction. Calling commit! outside of an explicit begin! block finalises the implicit transaction, persisting all changes made since the last commit.
insert into Names (first_name: "Charlie", last_name: "Parker");
insert into Names (first_name: "Charlie", last_name: "Brown");
commit!;
Explicit Transaction Blocks¶
For operations that must succeed or fail atomically, an explicit transaction block can be declared using begin! and closed with either commit! or rollback!.
Syntax:
begin!;
<statements>;
commit!;
begin!;
<statements>;
rollback!;
Commit example:
begin!;
insert into Puddles (
[x: 15.4, y: 45.8],
[x: 21.2, y: 3.2],
[x: 4.5, y: 2.4]
);
commit!;
Rollback example:
begin!;
insert into Puddles (x: 12.2, y: 4.5);
insert into Puddles (
[x: 14.4, y: 42.5],
[x: 20.2, y: 3.1],
[x: 4.0, y: 2.3]
);
rollback!;
When a rollback! is issued, all changes made within the enclosing begin! block are discarded and the database is returned to its state at the time of the begin!.