Add external exclusive write constructor
This change adds an external public constructor to the
SqliteStoreFactory to allow it to be created from an external, shared
Arc-RwLock-wrapped connection pool.
It also adds a function to create the wrapped pool, using the same
nomenclature as the various *_with_write_exclusivity constructors.
@@ -82,6 +82,14 @@ pub fn create_sqlite_connection_pool(
Ok(pool)
}
+pub fn create_sqlite_connection_pool_with_write_exclusivity(
+ conn_str: &str,
+) -> Result<Arc<RwLock<Pool<ConnectionManager<SqliteConnection>>>>, InternalError> {
+ Ok(Arc::new(RwLock::new(create_sqlite_connection_pool(
+ conn_str,
+ )?)))
+}
+
/// A `StoreFactory` backed by a SQLite database.
pub struct SqliteStoreFactory {
pool: Arc<RwLock<Pool<ConnectionManager<SqliteConnection>>>>,
@@ -94,6 +102,13 @@ impl SqliteStoreFactory {
pool: Arc::new(RwLock::new(pool)),
}
}
+
+ /// Create a new `SqliteStoreFactory` with shared write-exclusivity.
+ pub fn new_with_write_exclusivity(
+ pool: Arc<RwLock<Pool<ConnectionManager<SqliteConnection>>>>,
+ ) -> Self {
+ Self { pool }
+ }
}
impl StoreFactory for SqliteStoreFactory {
