pub struct PgDb { /* private fields */ }Expand description
Raw-SQL PostgreSQL database wrapper for multi-node deployments.
Implementations§
Source§impl PgDb
impl PgDb
Sourcepub async fn connect(database_url: &str) -> SlabResult<Self>
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.
Sourcepub async fn begin(&self) -> SlabResult<Transaction<'_, Postgres>>
pub async fn begin(&self) -> SlabResult<Transaction<'_, Postgres>>
Begins a new PostgreSQL transaction on the pool.
Sourcepub async fn init_system_tables(&self) -> SlabResult<()>
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.
Sourcepub async fn migrate(&self, migrator: &Migrator) -> SlabResult<()>
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.
Sourcepub async fn migrate_dir(&self, dir: &Path) -> SlabResult<()>
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.
Sourcepub async fn dump_schema_sql(&self) -> SlabResult<String>
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.
Sourcepub async fn execute_sql_file(&self, path: &Path) -> SlabResult<()>
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.
Sourcepub async fn ping(&self) -> SlabResult<()>
pub async fn ping(&self) -> SlabResult<()>
Executes SELECT 1 against the PostgreSQL pool to verify database connectivity.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for PgDb
impl !UnwindSafe for PgDb
impl Forget for PgDb
impl Freeze for PgDb
impl Move for PgDb
impl Send for PgDb
impl Sync for PgDb
impl Unpin for PgDb
impl UnsafeUnpin for PgDbwhere
*const ArcInner<PoolInner<Postgres>> is !null: UnsafeUnpin,
PhantomData<ArcInner<PoolInner<Postgres>>>: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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