Skip to main content

PgDb

Struct PgDb 

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

Raw-SQL PostgreSQL database wrapper for multi-node deployments.

Implementations§

Source§

impl PgDb

Source

pub async fn connect(database_url: &str) -> SlabResult<Self>

Connects to a PostgreSQL database with up to 20 pooled connections, a 5-second acquire timeout, a 5-minute idle timeout, and a 30-minute maximum connection lifetime.

Source

pub fn pool(&self) -> &PgPool

Returns the underlying sqlx PostgreSQL connection pool.

Source

pub async fn begin(&self) -> SlabResult<Transaction<'_, Postgres>>

Begins a new PostgreSQL transaction on the pool.

Source

pub async fn init_system_tables(&self) -> SlabResult<()>

Executes POSTGRES_SYSTEM_SCHEMA_SQL to create all 12 system tables idempotently, upgrading legacy slabs_jobs, slabs_idempotency_keys, slabs_blobs, and slabs_incidents tables in place when needed.

Source

pub async fn migrate(&self, migrator: &Migrator) -> SlabResult<()>

Creates system tables if missing and runs all pending migrations from migrator.

Wraps migration failures in SlabError::Internal.

Source

pub async fn migrate_dir(&self, dir: &Path) -> SlabResult<()>

Creates system tables if missing and runs all SQL migrations located in dir.

Wraps directory load and migration failures in SlabError::Internal.

Source

pub async fn dump_schema_sql(&self) -> SlabResult<String>

Exports public schema tables and indexes from information_schema.columns and pg_indexes.

Excludes _sqlx_% internal migration tables.

Source

pub async fn execute_sql_file(&self, path: &Path) -> SlabResult<()>

Reads a .sql file from disk and executes its statements against the PostgreSQL pool.

Intended for seed scripts such as slabs db seed. Empty or whitespace-only files are a no-op.

Source

pub async fn ping(&self) -> SlabResult<()>

Executes SELECT 1 against the PostgreSQL pool to verify database connectivity.

Trait Implementations§

Source§

impl Clone for PgDb

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 PgDb

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for PgDb

§

impl !UnwindSafe for PgDb

§

impl Forget for PgDb

§

impl Freeze for PgDb
where *const ArcInner<PoolInner<Postgres>> is !null: Freeze, PhantomData<ArcInner<PoolInner<Postgres>>>: Freeze,

§

impl Move for PgDb

§

impl Send for PgDb
where Arc<PoolInner<Postgres>>: Send,

§

impl Sync for PgDb
where Arc<PoolInner<Postgres>>: Sync,

§

impl Unpin for PgDb
where Arc<PoolInner<Postgres>>: Unpin,

§

impl UnsafeUnpin for PgDb
where *const ArcInner<PoolInner<Postgres>> is !null: UnsafeUnpin, PhantomData<ArcInner<PoolInner<Postgres>>>: UnsafeUnpin,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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