diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2021-04-29 12:37:09 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2021-04-30 10:07:08 +0200 |
commit | 79cb2f05559e1ed9e724efd4f5dbceca794e7162 (patch) | |
tree | 595995944c05483b66f8a1b69beb7ceaf7424da6 /odb/sqlite/connection-factory.cxx | |
parent | edaa6f79149a79d6b59efa711bbd5feeeb40513e (diff) |
Add serial_connection_factory
This factory can be used when the database access is guaranteed to be serial.
Diffstat (limited to 'odb/sqlite/connection-factory.cxx')
-rw-r--r-- | odb/sqlite/connection-factory.cxx | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/odb/sqlite/connection-factory.cxx b/odb/sqlite/connection-factory.cxx index 1269db3..1a1f85a 100644 --- a/odb/sqlite/connection-factory.cxx +++ b/odb/sqlite/connection-factory.cxx @@ -17,6 +17,40 @@ namespace odb namespace sqlite { // + // serial_connection_factory + // + + serial_connection_factory:: + ~serial_connection_factory () + { + // We should hold the last reference to the connection. + // + if (connection_ != 0) + assert (connection_.count () == 1); + } + + connection_ptr serial_connection_factory:: + create () + { + return connection_ptr (new (shared) connection (*this)); + } + + connection_ptr serial_connection_factory:: + connect () + { + return connection_; + } + + void serial_connection_factory:: + database (database_type& db) + { + connection_factory::database (db); + + if (!connection_) + connection_ = create (); + } + + // // single_connection_factory // |