pub struct OpenOptions { /* private fields */ }Expand description
Options that can be used to customize the opening of a SQLite database.
By default the database is opened in multi-threaded mode with the
SQLITE_OPEN_NOMUTEX set to ensure that Statement objects can be used
separately from the connection that constructed them.
To avoid this overhead in case you know how the statements will be used, you
can unset this by calling unset_no_mutex.
Implementations§
Source§impl OpenOptions
impl OpenOptions
Sourcepub fn read_only(self) -> Self
pub fn read_only(self) -> Self
The database is opened in read-only mode. If the database does not already exist, an error is returned.
Sourcepub fn read_write(self) -> Self
pub fn read_write(self) -> Self
The database is opened for reading and writing if possible, or reading only if the file is write protected by the operating system. In either case the database must already exist, otherwise an error is returned. For historical reasons, if opening in read-write mode fails due to OS-level permissions, an attempt is made to open it in read-only mode. sqlite3_db_readonly() can be used to determine whether the database is actually read-write.
Sourcepub fn create(self) -> Self
pub fn create(self) -> Self
The database is opened for reading and writing, and is created if it does not already exist.
Note that a mode option like read_write must be set, otherwise this
will cause an error when opening.
Sourcepub fn memory(self) -> Self
pub fn memory(self) -> Self
The database will be opened as an in-memory database. The database is named by the “filename” argument for the purposes of cache-sharing, if shared cache mode is enabled, but the “filename” is otherwise ignored.
Sourcepub fn no_mutex(self) -> Self
pub fn no_mutex(self) -> Self
The new database connection will use the “multi-thread” threading mode. This means that separate threads are allowed to use SQLite at the same time, as long as each thread is using a different database connection.
Sourcepub fn full_mutex(self) -> Self
pub fn full_mutex(self) -> Self
The new database connection will use the “serialized” threading mode. This means the multiple threads can safely attempt to use the same database connection at the same time. Mutexes will block any actual concurrency, but in this mode there is no harm in trying.
Sourcepub unsafe fn unsynchronized(self) -> Self
pub unsafe fn unsynchronized(self) -> Self
Set the database to be opened without the “multi-thread” threading
mode. The effect of calling this is that [open_full_mutex] and
[open_no_mutex] are unset.
§Safety
Prepared statements being separated from the connection object rely on
sqlite being in a multi-threaded mode to work safely. Unsetting this
option means you take responsibility for ensuring that no two threads
access the same connection even indirectly through Statement
simultaneously.
The database is opened with shared cache enabled, overriding the default shared cache setting provided. The use of shared cache mode is discouraged and hence shared cache capabilities may be omitted from many builds of SQLite. In such cases, this option is a no-op.
Sourcepub fn private_cache(self) -> Self
pub fn private_cache(self) -> Self
The database is opened with shared cache disabled, overriding the default shared cache setting provided.
Sourcepub fn extended_result_code(self) -> Self
pub fn extended_result_code(self) -> Self
The database connection comes up in “extended result code mode”. In
other words, the database behaves as if
[Connection::extended_result_codes] were called on the database
connection as soon as the connection is created. In addition to setting
the extended result code mode, this flag also causes the open call
to return an extended result code.
Sourcepub fn no_follow(self) -> Self
pub fn no_follow(self) -> Self
The database filename is not allowed to contain a symbolic link.
Sourcepub fn open(&self, path: impl AsRef<Path>) -> Result<Connection>
Available on crate feature std only.
pub fn open(&self, path: impl AsRef<Path>) -> Result<Connection>
std only.Open a database to the given path.
Note that it is possible to open an in-memory database by passing
":memory:" here, this call might require allocating depending on the
platform, so it should be avoided in favor of using memory. To avoid
allocating for regular paths, you can use open_c_str, however you
are responsible for ensuring the c-string is a valid path.
Sourcepub fn open_c_str(&self, name: &CStr) -> Result<Connection>
pub fn open_c_str(&self, name: &CStr) -> Result<Connection>
Open a database connection with a raw c-string.
This can be used to open in-memory databases by passing c":memory:" or
a regular open call with a filesystem path like
c"/path/to/database.sql".
Sourcepub fn open_memory(&self) -> Result<Connection>
pub fn open_memory(&self) -> Result<Connection>
Open an in-memory database.
Trait Implementations§
Source§impl Clone for OpenOptions
impl Clone for OpenOptions
Source§fn clone(&self) -> OpenOptions
fn clone(&self) -> OpenOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more