pub struct PgBackend { /* private fields */ }Expand description
A PostgreSQL database behind an sqlx pool.
Implementations§
Source§impl PgBackend
impl PgBackend
Sourcepub async fn migrate(
&self,
migrations: &[Migration],
) -> Result<MigrateReport, MigrateError>
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. See Migrates::migrate.
Sourcepub async fn verify_fresh(
&self,
migrations: &[Migration],
) -> Result<MigrateReport, MigrateError>
pub async fn verify_fresh( &self, migrations: &[Migration], ) -> Result<MigrateReport, MigrateError>
Prove that migrations install on an empty schema, in order, and leave nothing behind.
A scratch schema with a unique name is created, the migrations run in it on a pool of one
connection whose search_path is that schema (so the ledger is the scratch schema’s own), and
the schema is dropped afterwards, whether the run passed or failed. The report lists every
version as applied. The database being installed to is never touched: not its ledger, not its
tables.
Limits: a migration that names another schema explicitly, or creates an extension, role or other cluster-wide object, escapes the scratch schema; that is not detected. This is the PostgreSQL driver only.
Sourcepub async fn applied_versions(&self) -> Result<Vec<i64>, MigrateError>
pub async fn applied_versions(&self) -> Result<Vec<i64>, MigrateError>
The versions the ledger says succeeded, ascending; empty if there is no ledger yet.
Sourcepub async fn applied_checksums(
&self,
) -> Result<Vec<(i64, Vec<u8>)>, MigrateError>
pub async fn applied_checksums( &self, ) -> Result<Vec<(i64, Vec<u8>)>, MigrateError>
The ledger’s rows that succeeded, (version, checksum) ascending; empty if there is no ledger
yet. Reads the same rows Migrates::migrate checks against, so a caller can compare a
directory of migrations with a database without applying anything.
Source§impl PgBackend
impl PgBackend
Sourcepub async fn connect_with(
secret: &ConnectionSecret,
options: &ConnectOptions,
) -> Result<Self, RelError>
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).
Sourcepub async fn connection_is_encrypted(&self) -> Result<bool, RelError>
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
impl PgBackend
Sourcepub async fn connect(url: &str) -> Result<Self, RelError>
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.
Sourcepub async fn connect_secret(secret: &ConnectionSecret) -> Result<Self, RelError>
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.
Trait Implementations§
Source§impl Migrates for PgBackend
impl Migrates for PgBackend
Source§async fn migrate(
&self,
migrations: &[Migration],
) -> Result<MigrateReport, MigrateError>
async fn migrate( &self, migrations: &[Migration], ) -> Result<MigrateReport, MigrateError>
migrations in version order, skipping those already applied. Each migration runs in
its own transaction where the database can; 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§async fn applied_versions(&self) -> Result<Vec<i64>, MigrateError>
async fn applied_versions(&self) -> Result<Vec<i64>, MigrateError>
Source§impl RelationalBackend for PgBackend
impl RelationalBackend for PgBackend
Source§type Tx<'a> = PgTx<'a>
type Tx<'a> = PgTx<'a>
commit rolls it back.Source§async fn execute(&self, sql: &str, params: &[Value]) -> Result<u64, RelError>
async fn execute(&self, sql: &str, params: &[Value]) -> Result<u64, RelError>
Source§async fn query(&self, sql: &str, params: &[Value]) -> Result<Vec<Row>, RelError>
async fn query(&self, sql: &str, params: &[Value]) -> Result<Vec<Row>, RelError>
Source§async fn begin(&self, isolation: Isolation) -> Result<PgTx<'_>, RelError>
async fn begin(&self, isolation: Isolation) -> Result<PgTx<'_>, RelError>
isolation.Source§fn call_bound(&self) -> Option<Duration>
fn call_bound(&self) -> Option<Duration>
None (the default) means a
call waits as long as the server does. Every call that takes longer returns
RelError::Timeout.Source§fn with_lock_held<'a>(
&'a self,
lock_sql: &'a str,
at_most: Duration,
during: Pin<Box<dyn Future<Output = ()> + Send + 'a>>,
) -> impl Future<Output = Result<(), RelError>> + Send
fn with_lock_held<'a>( &'a self, lock_sql: &'a str, at_most: Duration, during: Pin<Box<dyn Future<Output = ()> + Send + 'a>>, ) -> impl Future<Output = Result<(), RelError>> + Send
kv.bounded_call: take lock_sql (a statement that locks a row) in a
transaction of its own, drive during while that lock is held, then roll back. during is
dropped, unfinished, after at_most, so a broken bound cannot hang the test. A backend that
enforces no bound returns RelError::Unsupported.Auto Trait Implementations§
impl !RefUnwindSafe for PgBackend
impl !UnwindSafe for PgBackend
impl Freeze for PgBackend
impl Send for PgBackend
impl Sync for PgBackend
impl Unpin for PgBackend
impl UnsafeUnpin for PgBackend
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,
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