Struct r2d2_sqlite::SqliteConnectionManager
source · [−]pub struct SqliteConnectionManager { /* private fields */ }
Expand description
An r2d2::ManageConnection
for rusqlite::Connection
s.
Implementations
sourceimpl SqliteConnectionManager
impl SqliteConnectionManager
sourcepub fn file<P: AsRef<Path>>(path: P) -> Self
pub fn file<P: AsRef<Path>>(path: P) -> Self
Creates a new SqliteConnectionManager
from file.
See rusqlite::Connection::open
sourcepub fn with_flags(self, flags: OpenFlags) -> Self
pub fn with_flags(self, flags: OpenFlags) -> Self
Converts SqliteConnectionManager
into one that sets OpenFlags upon
connection creation.
See rustqlite::OpenFlags
for a list of available flags.
sourcepub fn with_init<F>(self, init: F) -> Self where
F: Fn(&mut Connection) -> Result<(), Error> + Send + Sync + 'static,
pub fn with_init<F>(self, init: F) -> Self where
F: Fn(&mut Connection) -> Result<(), Error> + Send + Sync + 'static,
Converts SqliteConnectionManager
into one that calls an initialization
function upon connection creation. Could be used to set PRAGMAs, for
example.
Example
Make a SqliteConnectionManager
that sets the foreign_keys
pragma to
true for every connection.
let manager = SqliteConnectionManager::file("app.db")
.with_init(|c| c.execute_batch("PRAGMA foreign_keys=1;"));
Trait Implementations
sourceimpl Debug for SqliteConnectionManager
impl Debug for SqliteConnectionManager
sourceimpl ManageConnection for SqliteConnectionManager
impl ManageConnection for SqliteConnectionManager
type Connection = Connection
type Connection = Connection
The connection type this manager deals with.
sourcefn connect(&self) -> Result<Connection, Error>
fn connect(&self) -> Result<Connection, Error>
Attempts to create a new connection.
sourcefn is_valid(&self, conn: &mut Connection) -> Result<(), Error>
fn is_valid(&self, conn: &mut Connection) -> Result<(), Error>
Determines if the connection is still connected to the database. Read more
sourcefn has_broken(&self, _: &mut Connection) -> bool
fn has_broken(&self, _: &mut Connection) -> bool
Quickly determines if the connection is no longer usable. Read more
Auto Trait Implementations
impl !RefUnwindSafe for SqliteConnectionManager
impl Send for SqliteConnectionManager
impl Sync for SqliteConnectionManager
impl Unpin for SqliteConnectionManager
impl !UnwindSafe for SqliteConnectionManager
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more