pub struct SqliteStoreBuilder { /* private fields */ }sqlite only.Expand description
Builder for SqliteStore.
To create the database call SqliteStoreBuilder::build().
By default, the builder configures an in-memory database with a maximum number of 16 connections. The database is created if it doesn’t already exist and migrations are automatically run on start-up.
Implementations§
Source§impl SqliteStoreBuilder
impl SqliteStoreBuilder
Sourcepub fn memory() -> Self
pub fn memory() -> Self
Creates a new in-memory SqliteStoreBuilder using recommended configuration values.
The configuration values have been chosen to prevent the in-memory database being dropped when there are no active connections and the idle timeout or max lifetime limit is reached.
Sourcepub fn database_url(self, url: &str) -> Self
pub fn database_url(self, url: &str) -> Self
Sets the database URL.
If left unset, the database will use an ephemeral in-memory URL.
Sourcepub fn min_connections(self, min_connections: u32) -> Self
pub fn min_connections(self, min_connections: u32) -> Self
Sets the minimum number of connections to be maintained by the database pool.
If left unset, a minimum of 3 connections will be maintained.
Sourcepub fn max_connections(self, max_connections: u32) -> Self
pub fn max_connections(self, max_connections: u32) -> Self
Sets the maximum number of connections to be maintained by the database pool.
If left unset, a maximum of 16 connections will be maintained.
Sourcepub fn idle_timeout(self, timeout: impl Into<Option<Duration>>) -> Self
pub fn idle_timeout(self, timeout: impl Into<Option<Duration>>) -> Self
Set a maximum idle duration for individual connections.
Any connection that remains in the idle queue longer than this will be closed.
Sourcepub fn max_lifetime(self, lifetime: impl Into<Option<Duration>>) -> Self
pub fn max_lifetime(self, lifetime: impl Into<Option<Duration>>) -> Self
Set the maximum lifetime of individual connections.
Any connection with a lifetime greater than this will be closed.
When set to None, all connections live until either reaped by [idle_timeout] or
explicitly disconnected.
Infinite connections are not recommended due to the unfortunate reality of memory/resource leaks on the database-side. It is better to retire connections periodically (even if only once daily) to allow the database the opportunity to clean up data structures (parse trees, query metadata caches, thread-local storage, etc.) that are associated with a session.
Sourcepub fn create_database(self, create_database: bool) -> Self
pub fn create_database(self, create_database: bool) -> Self
Creates the database if it doesn’t already exist.
If left unset, the database will be created by default.
Sourcepub fn run_default_migrations(self, run_migrations: bool) -> Self
pub fn run_default_migrations(self, run_migrations: bool) -> Self
Sets whether pending migrations should be applied when the database is built.
If left unset, the database will apply any pending migrations.
Sourcepub async fn build(self) -> Result<SqliteStore, SqliteError>
pub async fn build(self) -> Result<SqliteStore, SqliteError>
Builds the SqliteStore.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SqliteStoreBuilder
impl RefUnwindSafe for SqliteStoreBuilder
impl Send for SqliteStoreBuilder
impl Sync for SqliteStoreBuilder
impl Unpin for SqliteStoreBuilder
impl UnsafeUnpin for SqliteStoreBuilder
impl UnwindSafe for SqliteStoreBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Declassify for T
impl<T> Declassify for T
type Declassified = T
fn declassify(self) -> T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more