aboutsummaryrefslogtreecommitdiff
path: root/bpkg/database.hxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-03-21 21:40:28 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-04-19 19:39:55 +0300
commit15dff3c592385466406732cd6ced809dc28cf2e2 (patch)
tree1da9f0738293eb7906d92ab010a79c689087b655 /bpkg/database.hxx
parent46842f6cf74d085ced382dd0c187f6a7a578913c (diff)
Implement build plan simulation
Diffstat (limited to 'bpkg/database.hxx')
-rw-r--r--bpkg/database.hxx54
1 files changed, 53 insertions, 1 deletions
diff --git a/bpkg/database.hxx b/bpkg/database.hxx
index f90aa6b..d97792a 100644
--- a/bpkg/database.hxx
+++ b/bpkg/database.hxx
@@ -25,7 +25,59 @@ namespace bpkg
using odb::session;
using odb::sqlite::database;
- using odb::sqlite::transaction;
+
+ // Transaction wrapper that allow the creation of dummy transactions (start
+ // is false) that in reality use an existing transaction.
+ //
+ struct transaction
+ {
+ using database_type = bpkg::database;
+
+ explicit
+ transaction (database_type& db, bool start = true)
+ : db_ (db), start_ (start), t_ () // Finalized.
+ {
+ if (start)
+ t_.reset (db.begin ());
+ }
+
+ void
+ commit ()
+ {
+ if (start_)
+ t_.commit ();
+ }
+
+ void
+ rollback ()
+ {
+ if (start_)
+ t_.rollback ();
+ }
+
+ database_type&
+ database ()
+ {
+ return db_;
+ }
+
+ static bool
+ has_current ()
+ {
+ return odb::sqlite::transaction::has_current ();
+ }
+
+ static odb::sqlite::transaction&
+ current ()
+ {
+ return odb::sqlite::transaction::current ();
+ }
+
+ private:
+ database_type& db_;
+ bool start_;
+ odb::sqlite::transaction t_;
+ };
database
open (const dir_path& configuration, tracer&, bool create = false);