OpenOptions

Struct OpenOptions 

Source
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

Source

pub fn new() -> Self

Create flags for opening a database connection.

Source

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.

Source

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.

Source

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.

Source

pub fn uri(self) -> Self

The filename can be interpreted as a URI if this flag is set.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn shared_cache(self) -> Self

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.

Source

pub fn private_cache(self) -> Self

The database is opened with shared cache disabled, overriding the default shared cache setting provided.

Source

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.

Source

pub fn no_follow(self) -> Self

The database filename is not allowed to contain a symbolic link.

Source

pub fn open(&self, path: impl AsRef<Path>) -> Result<Connection>

Available on crate feature 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.

Source

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".

Source

pub fn open_memory(&self) -> Result<Connection>

Open an in-memory database.

Trait Implementations§

Source§

impl Clone for OpenOptions

Source§

fn clone(&self) -> OpenOptions

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OpenOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for OpenOptions

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.