Skip to main content

DefaultDb

Struct DefaultDb 

Source
pub struct DefaultDb {
    pub(crate) pool: PgPool,
    pub(crate) acquired: Option<PoolConnection<Postgres>>,
}
Expand description

Default implementation that works without a transaction

Fields§

§pool: PgPool

db pool

§acquired: Option<PoolConnection<Postgres>>

when starting a transaction,

Implementations§

Source§

impl DefaultDb

Source

pub fn new(pool: PgPool) -> DefaultDb

Creates a new db instance.

Source

pub async fn from_env() -> Result<Self, DatabaseError>

Connects to a postgresql database, using environment variables. If the DATABASE_URL variable is set, connection options are derived from it. Otherwise, refer to [PgConnectOptions::new_without_pgpass()] for the specific environment variables used for configuration. If the ARMINIUS_LAZY environment variable is set to 1 or true, a lazy connection pool is created, meaning that an actual connection attempt is deferred until the first query is executed.

Source

pub async fn connect( pg_connect_options: PgConnectOptions, pg_pool_options: PgPoolOptions, lazy: bool, ) -> Result<Self, DatabaseError>

Connect to a PostgreSQL database endpoint. Creates a connection pool with the given [PgConnectOptions] and [PgPoolOptions].

Source

pub async fn run_migrations(&self) -> Result<(), Error>

Run the migrations defined in the migrations directory.

Source

pub async fn run_migrations_with( &self, migrator: &Migrator, ) -> Result<(), Error>

Run the migrations from the given Migrator

Source

pub async fn listener(&self) -> Result<PgListener, DatabaseError>

Create a PgListener using this instance’s connection pool

Source

pub async fn ping(&self) -> Result<(), DatabaseError>

Run a database connectivity check

Trait Implementations§

Source§

impl AsRef<Pool<Postgres>> for DefaultDb

Available on crate feature expose_pool only.

Exposes the inner connection pool. Unfortunately, this is still required because some tests are still using sqlx directly.

Source§

fn as_ref(&self) -> &PgPool

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for DefaultDb

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Database for DefaultDb

Source§

async fn connection(&mut self) -> Result<&mut RawPgConnection, DatabaseError>

Acquires a new connection from the pool. Read more
Source§

async fn begin_transaction<'c>( &'c mut self, ) -> Result<TransactedDb<'c>, DatabaseError>

Starts a new transaction, acquiring a fresh connection from the pool Once a transaction has been started, it is the callers’ responsibility to make changes permanent by committing it. If the transaction is dropped without being committed, all changes are rolled back.
Source§

impl Debug for DefaultDb

for whatever reason…

Source§

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

Formats the value using the given formatter. Read more

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.

§

impl<T> Instrument for T

§

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

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

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

Source§

type Output = T

Should always be Self
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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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