pub struct SqlxEngine { /* private fields */ }Expand description
SQLx-based query engine for Prax.
This engine provides compile-time checked queries through SQLx, supporting PostgreSQL, MySQL, and SQLite.
Two modes, controlled by the tx field:
- Pool mode (
tx == None, the default): each query acquires a fresh connection from the pool and drops it after the call. - Transaction mode (
tx == Some(handle)): every query routes through the transaction’s pinned connection. The tx-bound engine is built byQueryEngine::transaction, which issuesCOMMITorROLLBACKon the same transaction when the closure resolves.
§Example
use prax_sqlx::{SqlxEngine, SqlxConfig};
let config = SqlxConfig::from_url("postgres://localhost/mydb")?;
let engine = SqlxEngine::new(config).await?;
// Execute queries
let count = engine.count_table("users", None).await?;Implementations§
Source§impl SqlxEngine
impl SqlxEngine
Sourcepub async fn new(config: SqlxConfig) -> SqlxResult<Self>
pub async fn new(config: SqlxConfig) -> SqlxResult<Self>
Create a new SQLx engine from configuration.
Sourcepub fn backend(&self) -> DatabaseBackend
pub fn backend(&self) -> DatabaseBackend
Get the database backend type.
Sourcepub async fn raw_query_many(
&self,
sql: &str,
params: &[FilterValue],
) -> SqlxResult<Vec<SqlxRow>>
pub async fn raw_query_many( &self, sql: &str, params: &[FilterValue], ) -> SqlxResult<Vec<SqlxRow>>
Execute a raw SQL query and return multiple rows.
Sourcepub async fn raw_query_one(
&self,
sql: &str,
params: &[FilterValue],
) -> SqlxResult<SqlxRow>
pub async fn raw_query_one( &self, sql: &str, params: &[FilterValue], ) -> SqlxResult<SqlxRow>
Execute a raw SQL query and return a single row.
Sourcepub async fn raw_query_optional(
&self,
sql: &str,
params: &[FilterValue],
) -> SqlxResult<Option<SqlxRow>>
pub async fn raw_query_optional( &self, sql: &str, params: &[FilterValue], ) -> SqlxResult<Option<SqlxRow>>
Execute a raw SQL query and return an optional row.
Sourcepub async fn raw_execute(
&self,
sql: &str,
params: &[FilterValue],
) -> SqlxResult<u64>
pub async fn raw_execute( &self, sql: &str, params: &[FilterValue], ) -> SqlxResult<u64>
Execute a SQL statement (INSERT, UPDATE, DELETE) and return affected rows.
Sourcepub async fn count_table(
&self,
table: &str,
filter: Option<&str>,
) -> SqlxResult<u64>
pub async fn count_table( &self, table: &str, filter: Option<&str>, ) -> SqlxResult<u64>
Count rows in a table with optional filter.
Trait Implementations§
Source§impl Clone for SqlxEngine
impl Clone for SqlxEngine
Source§fn clone(&self) -> SqlxEngine
fn clone(&self) -> SqlxEngine
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl QueryEngine for SqlxEngine
impl QueryEngine for SqlxEngine
Source§fn dialect(&self) -> &dyn SqlDialect
fn dialect(&self) -> &dyn SqlDialect
Source§fn query_many<T: Model + FromRow + Send + 'static>(
&self,
sql: &str,
params: Vec<FilterValue>,
) -> BoxFuture<'_, QueryResult<Vec<T>>>
fn query_many<T: Model + FromRow + Send + 'static>( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<Vec<T>>>
Source§fn query_one<T: Model + FromRow + Send + 'static>(
&self,
sql: &str,
params: Vec<FilterValue>,
) -> BoxFuture<'_, QueryResult<T>>
fn query_one<T: Model + FromRow + Send + 'static>( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<T>>
Source§fn query_optional<T: Model + FromRow + Send + 'static>(
&self,
sql: &str,
params: Vec<FilterValue>,
) -> BoxFuture<'_, QueryResult<Option<T>>>
fn query_optional<T: Model + FromRow + Send + 'static>( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<Option<T>>>
Source§fn execute_insert<T: Model + FromRow + Send + 'static>(
&self,
sql: &str,
params: Vec<FilterValue>,
) -> BoxFuture<'_, QueryResult<T>>
fn execute_insert<T: Model + FromRow + Send + 'static>( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<T>>
Source§fn execute_update<T: Model + FromRow + Send + 'static>(
&self,
sql: &str,
params: Vec<FilterValue>,
) -> BoxFuture<'_, QueryResult<Vec<T>>>
fn execute_update<T: Model + FromRow + Send + 'static>( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<Vec<T>>>
Source§fn execute_delete(
&self,
sql: &str,
params: Vec<FilterValue>,
) -> BoxFuture<'_, QueryResult<u64>>
fn execute_delete( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<u64>>
Source§fn execute_raw(
&self,
sql: &str,
params: Vec<FilterValue>,
) -> BoxFuture<'_, QueryResult<u64>>
fn execute_raw( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<u64>>
Source§fn count(
&self,
sql: &str,
params: Vec<FilterValue>,
) -> BoxFuture<'_, QueryResult<u64>>
fn count( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<u64>>
Source§fn aggregate_query(
&self,
sql: &str,
params: Vec<FilterValue>,
) -> BoxFuture<'_, QueryResult<Vec<HashMap<String, FilterValue>>>>
fn aggregate_query( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<Vec<HashMap<String, FilterValue>>>>
crate::filter::FilterValue
per result row. Read moreSource§fn in_transaction(&self) -> bool
fn in_transaction(&self) -> bool
Source§fn transaction<'a, R, Fut, F>(&'a self, f: F) -> BoxFuture<'a, QueryResult<R>>
fn transaction<'a, R, Fut, F>(&'a self, f: F) -> BoxFuture<'a, QueryResult<R>>
impl SupportsScalarSubqueryInSelect for SqlxEngine
SQLx routes exclusively to SQL backends (Postgres, MySQL, SQLite), all of
which support scalar subqueries in SELECT. Implementing this marker here
lets callers use [FindManyOperation::with_scalar_projection] and its
siblings on SqlxEngine just like the individual SQL engine crates.
Auto Trait Implementations§
impl !RefUnwindSafe for SqlxEngine
impl !UnwindSafe for SqlxEngine
impl Freeze for SqlxEngine
impl Send for SqlxEngine
impl Sync for SqlxEngine
impl Unpin for SqlxEngine
impl UnsafeUnpin for SqlxEngine
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