pub struct PostgresOptions { /* private fields */ }Expand description
Where the store keeps its tables and how it talks to the database.
The defaults are what PostgresStore::connect uses: tables found
through search_path, migration history in _sqlx_migrations, prepared
statements cached per connection, and 10 connections.
Implementations§
Source§impl PostgresOptions
impl PostgresOptions
Sourcepub fn schema(self, schema: impl Into<String>) -> Self
pub fn schema(self, schema: impl Into<String>) -> Self
Keeps the store’s tables in schema and names it in every query, so
search_path does not matter. The migration history goes in
schema._sqlx_migrations, apart from any other sqlx migrations in
the database.
schema is a name, used exactly as written (case included), not SQL.
migrate creates it if it does not exist.
Sourcepub fn transaction_pooling(self, enabled: bool) -> Self
pub fn transaction_pooling(self, enabled: bool) -> Self
For a pool that reaches Postgres through PgBouncer, or another pooler, in transaction mode.
Such a pooler may hand each transaction, and each statement outside
one, to a different server connection. So no statement is prepared
for reuse, and every store operation runs inside a transaction, so
that a statement’s parse, bind and execution all reach the same
server. Reads that would otherwise run alone cost a BEGIN and a
COMMIT more.
The pool is the application’s, so its connect options are too. Two of
sqlx’s matter behind a pooler: turn off the extra_float_digits
startup parameter (PgConnectOptions::extra_float_digits(None))
unless the pooler ignores it, and do not set search_path through
PgConnectOptions::options, which a pooler does not pass on; use
schema instead. The store has no float columns, so
it does not depend on extra_float_digits.
Sourcepub fn max_connections(self, max: u32) -> Self
pub fn max_connections(self, max: u32) -> Self
The size of the pool connect and
connect_with open; 10 by default.
attach uses the pool it is given as it is.
Sourcepub async fn connect(&self, url: &str) -> Result<PostgresStore, StoreError>
pub async fn connect(&self, url: &str) -> Result<PostgresStore, StoreError>
Connects to url, applies migrations, and attaches.
Migrating needs a direct connection (see migrate),
so url must not go through a pooler in transaction mode; for that,
migrate directly and attach to the
pooled pool.
§Errors
StoreError::Backend if connecting or migrating fails.
Sourcepub async fn connect_with(
&self,
options: PgConnectOptions,
) -> Result<PostgresStore, StoreError>
pub async fn connect_with( &self, options: PgConnectOptions, ) -> Result<PostgresStore, StoreError>
Connects with options, applies migrations, and attaches. Like
connect, it needs a direct connection.
§Errors
StoreError::Backend if connecting or migrating fails.
Sourcepub async fn migrate(&self, pool: &PgPool) -> Result<(), StoreError>
pub async fn migrate(&self, pool: &PgPool) -> Result<(), StoreError>
Applies the store’s migrations through pool.
pool must reach Postgres directly, not through a pooler in
transaction mode: migrations hold a session-level advisory lock, so
concurrent callers are safe. Through such a pooler the lock can be
left held on a server connection, blocking every later migration in
the database, the application’s included. With a schema, the
connection used is closed afterwards instead of going back to the
pool, so pool keeps its own search_path.
§Errors
StoreError::Backend if migrating fails, or if the history table
holds a different migration under one of the store’s versions (as
when it is shared with an application’s migrations; give the store a
schema of its own).
Sourcepub async fn attach(&self, pool: PgPool) -> Result<PostgresStore, StoreError>
pub async fn attach(&self, pool: PgPool) -> Result<PostgresStore, StoreError>
Uses pool without migrating; pool may go through a pooler (see
transaction_pooling for its connect
options).
Checks that every migration this version needs has been applied, so a
missing migrate fails here rather than on the first
effect.
§Errors
StoreError::Backend if the database is unreachable or a migration
is missing or not the store’s own.
Trait Implementations§
Source§impl Clone for PostgresOptions
impl Clone for PostgresOptions
Source§impl Debug for PostgresOptions
impl Debug for PostgresOptions
Auto Trait Implementations§
impl Freeze for PostgresOptions
impl RefUnwindSafe for PostgresOptions
impl Send for PostgresOptions
impl Sync for PostgresOptions
impl Unpin for PostgresOptions
impl UnsafeUnpin for PostgresOptions
impl UnwindSafe for PostgresOptions
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