pub struct Connection { /* private fields */ }
Expand description
A connection to a SQLite database.
All operations on an Archive
must happen within the context of a Transaction
. You can
use this connection to begin a transaction. Typically, you’ll use Connection::exec
to
execute a closure within a transaction.
You can open a connection to a SQLite archive using one of these methods:
Implementations§
Source§impl Connection
impl Connection
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
Open a connection to the SQLite archive at path
.
This does not create a new SQLite archive if one does not already exist.
§Errors
CannotOpen
: The database could not be opened because it does not exist.NotADatabase
: The file atpath
is not a SQLite database.
Sourcepub fn create<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn create<P: AsRef<Path>>(path: P) -> Result<Self>
Create or open the SQLite archive at path
.
This creates the SQLite archive if it does not already exist.
§Errors
NotADatabase
: The file atpath
exists but is not a SQLite database.
Sourcepub fn create_new<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn create_new<P: AsRef<Path>>(path: P) -> Result<Self>
Create a new SQLite archive at path
.
This fails if the SQLite archive does not already exist.
§Errors
SqlarAlreadyExists
: A SQLite archive already exists atpath
.
Sourcepub fn open_readonly<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn open_readonly<P: AsRef<Path>>(path: P) -> Result<Self>
Open a read-only connection to the SQLite archive at path
.
This does not create a new SQLite archive if one does not already exist.
§Errors
CannotOpen
: The database could not be opened because it does not exist.NotADatabase
: The file atpath
is not a SQLite database.
Sourcepub fn open_in_memory() -> Result<Self>
pub fn open_in_memory() -> Result<Self>
Create a new in-memory SQLite archive.
Sourcepub fn transaction(&mut self) -> Result<Transaction<'_>>
pub fn transaction(&mut self) -> Result<Transaction<'_>>
Start a new transaction.
Sourcepub fn transaction_with(
&mut self,
behavior: TransactionBehavior,
) -> Result<Transaction<'_>>
pub fn transaction_with( &mut self, behavior: TransactionBehavior, ) -> Result<Transaction<'_>>
Start a new transaction with the given TransactionBehavior
.
Sourcepub fn exec<T, E, F>(&mut self, f: F) -> Result<T, E>
pub fn exec<T, E, F>(&mut self, f: F) -> Result<T, E>
Execute the given function within a new transaction.
See Transaction::exec
.
Sourcepub fn exec_with<T, E, F>(
&mut self,
behavior: TransactionBehavior,
f: F,
) -> Result<T, E>
pub fn exec_with<T, E, F>( &mut self, behavior: TransactionBehavior, f: F, ) -> Result<T, E>
Execute the given function within a new transaction with the given
TransactionBehavior
.,
See Transaction::exec
.