pub enum DatabaseClient {
Postgres(PgPool),
}Expand description
The database client, wrapping an sqlx connection pool.
Supports PostgreSQL and SQLite via feature flags.
Variants§
Implementations§
Source§impl DatabaseClient
impl DatabaseClient
Sourcepub async fn connect_postgres(url: &str) -> Result<Self, FerriormError>
pub async fn connect_postgres(url: &str) -> Result<Self, FerriormError>
Connect to a PostgreSQL database.
Sourcepub async fn connect_postgres_with_config(
url: &str,
config: &PoolConfig,
) -> Result<Self, FerriormError>
pub async fn connect_postgres_with_config( url: &str, config: &PoolConfig, ) -> Result<Self, FerriormError>
Connect to a PostgreSQL database with custom pool configuration.
Sourcepub async fn connect(url: &str) -> Result<Self, FerriormError>
pub async fn connect(url: &str) -> Result<Self, FerriormError>
Connect by auto-detecting the database type from the URL.
Sourcepub async fn connect_with_config(
url: &str,
config: &PoolConfig,
) -> Result<Self, FerriormError>
pub async fn connect_with_config( url: &str, config: &PoolConfig, ) -> Result<Self, FerriormError>
Connect by auto-detecting the database type from the URL, using custom pool configuration.
Sourcepub fn pg_pool(&self) -> Result<&PgPool, FerriormError>
pub fn pg_pool(&self) -> Result<&PgPool, FerriormError>
Get a reference to the underlying PostgreSQL pool for raw queries.
Returns an error if this client is not connected to PostgreSQL.
Sourcepub async fn disconnect(self)
pub async fn disconnect(self)
Close the connection pool.
Sourcepub async fn raw_fetch_all_pg<T>(
&self,
sql: &str,
) -> Result<Vec<T>, FerriormError>
pub async fn raw_fetch_all_pg<T>( &self, sql: &str, ) -> Result<Vec<T>, FerriormError>
Execute raw SQL and return all rows mapped to T (PostgreSQL).
Sourcepub async fn raw_fetch_one_pg<T>(&self, sql: &str) -> Result<T, FerriormError>
pub async fn raw_fetch_one_pg<T>(&self, sql: &str) -> Result<T, FerriormError>
Execute raw SQL and return exactly one row mapped to T (PostgreSQL).
Sourcepub async fn raw_fetch_optional_pg<T>(
&self,
sql: &str,
) -> Result<Option<T>, FerriormError>
pub async fn raw_fetch_optional_pg<T>( &self, sql: &str, ) -> Result<Option<T>, FerriormError>
Execute raw SQL and return an optional row mapped to T (PostgreSQL).
Sourcepub async fn raw_execute_pg(&self, sql: &str) -> Result<u64, FerriormError>
pub async fn raw_execute_pg(&self, sql: &str) -> Result<u64, FerriormError>
Execute raw SQL without returning rows (PostgreSQL). Returns the number of rows affected.
Sourcepub async fn fetch_all_pg<'q, T>(
&self,
qb: QueryBuilder<'q, Postgres>,
) -> Result<Vec<T>, FerriormError>
pub async fn fetch_all_pg<'q, T>( &self, qb: QueryBuilder<'q, Postgres>, ) -> Result<Vec<T>, FerriormError>
Execute a query builder against the appropriate pool, returning all rows.
pub async fn fetch_optional_pg<'q, T>( &self, qb: QueryBuilder<'q, Postgres>, ) -> Result<Option<T>, FerriormError>
pub async fn fetch_one_pg<'q, T>( &self, qb: QueryBuilder<'q, Postgres>, ) -> Result<T, FerriormError>
pub async fn execute_pg<'q>( &self, qb: QueryBuilder<'q, Postgres>, ) -> Result<u64, FerriormError>
Trait Implementations§
Source§impl Clone for DatabaseClient
impl Clone for DatabaseClient
Source§fn clone(&self) -> DatabaseClient
fn clone(&self) -> DatabaseClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for DatabaseClient
impl !RefUnwindSafe for DatabaseClient
impl Send for DatabaseClient
impl Sync for DatabaseClient
impl Unpin for DatabaseClient
impl UnsafeUnpin for DatabaseClient
impl !UnwindSafe for DatabaseClient
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