From efcea3a80da7c4479d5fe168435ecc9fd06bdc72 Mon Sep 17 00:00:00 2001
From: John Turner <jturner.usa@gmail.com>
Date: Sun, 14 Sep 2025 00:16:10 -0400
Subject: Squashed 'subprojects/boost-sqlite/' content from commit 3378e35

git-subtree-dir: subprojects/boost-sqlite
git-subtree-split: 3378e353705271e569cf4ba15c467b840a39798c
---
 doc/reference/transaction.adoc | 104 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 104 insertions(+)
 create mode 100644 doc/reference/transaction.adoc

(limited to 'doc/reference/transaction.adoc')

diff --git a/doc/reference/transaction.adoc b/doc/reference/transaction.adoc
new file mode 100644
index 0000000..b6bc449
--- /dev/null
+++ b/doc/reference/transaction.adoc
@@ -0,0 +1,104 @@
+== `sqlite/transaction.hpp`
+
+=== `transaction`
+
+A simple transaction guard implementing RAAI for transactions
+
+.Definition
+[source,cpp]
+----
+struct transaction
+{
+  // The mode of the transaction
+  enum behaviour {deferred, immediate, exclusive};
+  // A tag to use, to adopt an already initiated transaction.
+  constexpr static struct adopt_transaction_t {} adopt_transaction{};
+
+  // Create transaction guard on an existing transaction
+  transaction(connection & conn, adopt_transaction_t);
+
+
+  // Create transaction guard and initiate a transaction
+  transaction(connection & conn);
+
+  // Create transaction guard and initiate a transaction with the defined behaviour
+  transaction(connection & conn, behaviour b) ;
+
+  // see https://www.sqlite.org/lang_transaction.html re noexcept
+  // rollback the transaction if not committed.
+  ~transaction() noexcept(SQLITE_VERSION_NUMBER >= 3007011);
+
+
+  // Commit the transaction.
+  void commit();
+  void commit(system::error_code & ec, error_info & ei);
+  // Rollback the transaction explicitly.
+  void rollback();
+  void rollback(system::error_code & ec, error_info & ei);
+
+};
+----
+
+
+
+.Example
+[source,cpp]
+----
+sqlite::connection conn;
+conn.connect("./my-database.db");
+
+sqlite::transaction t{conn};
+conn.prepare("insert into log (text) values ($1)").execute(std::make_tuple("booting up"));
+t.commit();
+----
+
+=== `savepoint`
+
+A simple transaction guard implementing RAAI for savepoints. Savepoints can be used recursively.
+
+.Definition
+[source,cpp]
+----
+
+struct savepoint
+{
+  // A tag to use, to adopt an already initiated transaction.
+  constexpr static transaction::adopt_transaction_t adopt_transaction{};
+
+  // Create savepoint guard on an existing savepoint
+  savepoint(connection & conn, std::string name, transaction::adopt_transaction_t);
+
+  // Create transaction guard and initiate it
+  savepoint(connection & conn, std::string name);
+
+  // rollback to the savepoint if not committed.
+  ~savepoint() noexcept(SQLITE_VERSION_NUMBER >= 3007011);
+
+  // Commit/Release the transaction.
+  void commit();
+  void commit(system::error_code & ec, error_info & ei);
+
+  void release();
+  void release(system::error_code & ec, error_info & ei);
+
+  // Rollback the transaction explicitly.
+  void rollback();
+  void rollback(system::error_code & ec, error_info & ei);
+  // The name of the savepoint.
+
+  const std::string & name() const;
+};
+----
+
+
+.Example
+[source,cpp]
+----
+sqlite::connection conn;
+conn.connect("./my-database.db");
+
+sqlite::savepoint t{conn, "my-savepoint};
+conn.prepare("insert into log (text) values ($1)").execute(std::make_tuple("booting up"));
+t.commit();
+----
+
-- 
cgit v1.2.3

