Skip to main content

PgBackend

Struct PgBackend 

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

A PostgreSQL database behind an sqlx pool.

Implementations§

Source§

impl PgBackend

Source

pub async fn migrate( &self, migrations: &[Migration], ) -> Result<MigrateReport, MigrateError>

Apply migrations in version order, skipping those already applied, in the ledger _sqlx_migrations of the connection’s current schema.

Each migration runs in its own transaction. Refuses (applying nothing further) if an applied migration’s text has changed, if the database has applied a version the program does not know, or if a migration is recorded as dirty.

Source

pub async fn applied_versions(&self) -> Result<Vec<i64>, MigrateError>

The versions the ledger says succeeded, ascending; empty if there is no ledger yet.

Source§

impl PgBackend

Source

pub async fn connect_with( secret: &ConnectionSecret, options: &ConnectOptions, ) -> Result<Self, RelError>

Connect with an explicit TLS policy and pool bounds, to a connection string held as a ConnectionSecret (resolved here, never printed).

Source

pub async fn connection_is_encrypted(&self) -> Result<bool, RelError>

Whether the connection this backend uses is encrypted, as the server reports it (pg_stat_ssl), not as the client was asked.

Source§

impl PgBackend

Source

pub async fn connect(url: &str) -> Result<Self, RelError>

Connect with default pool settings and read the server version.

Prefer PgBackend::connect_secret: a &str URL is one Debug print from a log file.

Source

pub async fn connect_secret(secret: &ConnectionSecret) -> Result<Self, RelError>

Connect with a connection string held as a persistant_relational::ConnectionSecret: resolved here, never printed, never part of an error.

Source

pub async fn from_pool(pool: PgPool) -> Result<Self, RelError>

Wrap an existing pool (a program that already owns one keeps it).

Source

pub fn pool(&self) -> &PgPool

The concrete pool: for sqlx::query! and anything this layer does not carry.

Trait Implementations§

Source§

impl Clone for PgBackend

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 Debug for PgBackend

Source§

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

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

impl RelationalBackend for PgBackend

Source§

type Tx<'a> = PgTx<'a>

A transaction on this backend. Dropping it without commit rolls it back.
Source§

fn backend(&self) -> &str

The backend’s name as it appears in matrix rows (postgres).
Source§

fn version(&self) -> &str

The server version string as it appears in matrix rows (16.15).
Source§

fn dialect(&self) -> Dialect

The dialect statements must be written in.
Source§

async fn execute(&self, sql: &str, params: &[Value]) -> Result<u64, RelError>

Run a statement that returns no rows; the result is the number of rows affected.
Source§

async fn query(&self, sql: &str, params: &[Value]) -> Result<Vec<Row>, RelError>

Run a statement and return its rows.
Source§

async fn begin(&self) -> Result<PgTx<'_>, RelError>

Begin a transaction.

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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