pub struct DefaultDb {
pub(crate) pool: PgPool,
pub(crate) acquired: Option<PoolConnection<Postgres>>,
}Expand description
Default implementation that works without a transaction
Fields§
§pool: PgPooldb pool
acquired: Option<PoolConnection<Postgres>>when starting a transaction,
Implementations§
Source§impl DefaultDb
impl DefaultDb
Sourcepub async fn from_env() -> Result<Self, DatabaseError>
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.
Sourcepub async fn connect(
pg_connect_options: PgConnectOptions,
pg_pool_options: PgPoolOptions,
lazy: bool,
) -> Result<Self, DatabaseError>
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].
Sourcepub async fn run_migrations(&self) -> Result<(), Error>
pub async fn run_migrations(&self) -> Result<(), Error>
Run the migrations defined in the migrations directory.
Sourcepub async fn run_migrations_with(
&self,
migrator: &Migrator,
) -> Result<(), Error>
pub async fn run_migrations_with( &self, migrator: &Migrator, ) -> Result<(), Error>
Run the migrations from the given Migrator
Sourcepub async fn listener(&self) -> Result<PgListener, DatabaseError>
pub async fn listener(&self) -> Result<PgListener, DatabaseError>
Create a PgListener using this instance’s connection pool
Sourcepub async fn ping(&self) -> Result<(), DatabaseError>
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.
impl AsRef<Pool<Postgres>> for DefaultDb
expose_pool only.Exposes the inner connection pool. Unfortunately, this is still required because some tests are still using sqlx directly.
Source§impl Database for DefaultDb
impl Database for DefaultDb
Source§async fn connection(&mut self) -> Result<&mut RawPgConnection, DatabaseError>
async fn connection(&mut self) -> Result<&mut RawPgConnection, DatabaseError>
Source§async fn begin_transaction<'c>(
&'c mut self,
) -> Result<TransactedDb<'c>, DatabaseError>
async fn begin_transaction<'c>( &'c mut self, ) -> Result<TransactedDb<'c>, DatabaseError>
Auto Trait Implementations§
impl !RefUnwindSafe for DefaultDb
impl !UnwindSafe for DefaultDb
impl Freeze for DefaultDb
impl Send for DefaultDb
impl Sync for DefaultDb
impl Unpin for DefaultDb
impl UnsafeUnpin for DefaultDb
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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