Skip to main content

ConnectOptions

Struct ConnectOptions 

Source
pub struct ConnectOptions { /* private fields */ }
Expand description

Defines the configuration options of a database

Implementations§

Source§

impl ConnectOptions

Source

pub fn new<T>(url: T) -> Self
where T: Into<String>,

Create new ConnectOptions for a Database by passing in a URI string

Source

pub fn get_url(&self) -> &str

Get the database URL of the pool

Source

pub fn max_connections(&mut self, value: u32) -> &mut Self

Set the maximum number of connections of the pool

Source

pub fn get_max_connections(&self) -> Option<u32>

Get the maximum number of connections of the pool, if set

Source

pub fn min_connections(&mut self, value: u32) -> &mut Self

Set the minimum number of connections of the pool

Source

pub fn get_min_connections(&self) -> Option<u32>

Get the minimum number of connections of the pool, if set

Source

pub fn connect_timeout(&mut self, value: Duration) -> &mut Self

Set the timeout duration when acquiring a connection

Source

pub fn get_connect_timeout(&self) -> Option<Duration>

Get the timeout duration when acquiring a connection, if set

Source

pub fn idle_timeout<T>(&mut self, value: T) -> &mut Self
where T: Into<Option<Duration>>,

Set the idle duration before closing a connection.

Source

pub fn get_idle_timeout(&self) -> Option<Option<Duration>>

Get the idle duration before closing a connection, if set

Source

pub fn acquire_timeout(&mut self, value: Duration) -> &mut Self

Set the maximum amount of time to spend waiting for acquiring a connection

Source

pub fn get_acquire_timeout(&self) -> Option<Duration>

Get the maximum amount of time to spend waiting for acquiring a connection

Source

pub fn max_lifetime<T>(&mut self, lifetime: T) -> &mut Self
where T: Into<Option<Duration>>,

Set the maximum lifetime of individual connections.

Source

pub fn get_max_lifetime(&self) -> Option<Option<Duration>>

Get the maximum lifetime of individual connections, if set

Source

pub fn sqlx_logging(&mut self, value: bool) -> &mut Self

Enable SQLx statement logging (default true)

Source

pub fn get_sqlx_logging(&self) -> bool

Get whether SQLx statement logging is enabled

Source

pub fn sqlx_logging_level(&mut self, level: LevelFilter) -> &mut Self

Set SQLx statement logging level (default INFO). (ignored if sqlx_logging is false)

Source

pub fn sqlx_slow_statements_logging_settings( &mut self, level: LevelFilter, duration: Duration, ) -> &mut Self

Set SQLx slow statements logging level and duration threshold (default LevelFilter::Off). (ignored if sqlx_logging is false)

Source

pub fn get_sqlx_logging_level(&self) -> LevelFilter

Get the level of SQLx statement logging

Source

pub fn get_sqlx_slow_statements_logging_settings( &self, ) -> (LevelFilter, Duration)

Get the SQLx slow statements logging settings

Source

pub fn sqlcipher_key<T>(&mut self, value: T) -> &mut Self
where T: Into<Cow<'static, str>>,

set key for sqlcipher

Source

pub fn set_schema_search_path<T>(&mut self, schema_search_path: T) -> &mut Self
where T: Into<String>,

Set schema search path (PostgreSQL only)

Source

pub fn set_application_name<T>(&mut self, application_name: T) -> &mut Self
where T: Into<String>,

Set application name (PostgreSQL only)

Source

pub fn statement_timeout(&mut self, value: Duration) -> &mut Self

Set the statement timeout (PostgreSQL only).

This sets the PostgreSQL statement_timeout parameter via the connection options, causing the server to abort any statement that exceeds the specified duration. The timeout is applied at connection time and does not require an extra roundtrip.

Has no effect on MySQL or SQLite connections.

Source

pub fn get_statement_timeout(&self) -> Option<Duration>

Get the statement timeout, if set

Source

pub fn test_before_acquire(&mut self, value: bool) -> &mut Self

If true, the connection will be pinged upon acquiring from the pool (default true).

Source

pub fn connect_lazy(&mut self, value: bool) -> &mut Self

If set to true, the db connection pool will be created using SQLx’s connect_lazy method.

Source

pub fn get_connect_lazy(&self) -> bool

Get whether DB connections will be established when the pool is created or only as needed.

Source

pub fn after_connect<F>(&mut self, f: F) -> &mut Self
where F: Fn(DatabaseConnection) -> Result<(), DbErr> + 'static,

Set a callback function that will be called after a new connection is established.

Trait Implementations§

Source§

impl Clone for ConnectOptions

Source§

fn clone(&self) -> ConnectOptions

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 ConnectOptions

Source§

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

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

impl<T> From<T> for ConnectOptions
where T: Into<String>,

Source§

fn from(s: T) -> ConnectOptions

Converts to this type from the input type.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more