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.
§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
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl QueryEngine for SqlxEngine
impl QueryEngine for SqlxEngine
Source§fn query_many<T: Model + Send + 'static>(
&self,
sql: &str,
params: Vec<FilterValue>,
) -> BoxFuture<'_, QueryResult<Vec<T>>>
fn query_many<T: Model + Send + 'static>( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<Vec<T>>>
Execute a SELECT query and return rows.
Source§fn query_one<T: Model + Send + 'static>(
&self,
sql: &str,
params: Vec<FilterValue>,
) -> BoxFuture<'_, QueryResult<T>>
fn query_one<T: Model + Send + 'static>( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<T>>
Execute a SELECT query expecting one result.
Source§fn query_optional<T: Model + Send + 'static>(
&self,
sql: &str,
params: Vec<FilterValue>,
) -> BoxFuture<'_, QueryResult<Option<T>>>
fn query_optional<T: Model + Send + 'static>( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<Option<T>>>
Execute a SELECT query expecting zero or one result.
Source§fn execute_insert<T: Model + Send + 'static>(
&self,
sql: &str,
params: Vec<FilterValue>,
) -> BoxFuture<'_, QueryResult<T>>
fn execute_insert<T: Model + Send + 'static>( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<T>>
Execute an INSERT query and return the created row.
Source§fn execute_update<T: Model + Send + 'static>(
&self,
sql: &str,
params: Vec<FilterValue>,
) -> BoxFuture<'_, QueryResult<Vec<T>>>
fn execute_update<T: Model + Send + 'static>( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<Vec<T>>>
Execute an UPDATE query and return affected rows.
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>>
Execute a DELETE query and return affected rows count.
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>>
Execute a raw SQL query.
Source§fn count(
&self,
sql: &str,
params: Vec<FilterValue>,
) -> BoxFuture<'_, QueryResult<u64>>
fn count( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<u64>>
Get a count of records.
Auto Trait Implementations§
impl Freeze for SqlxEngine
impl !RefUnwindSafe for SqlxEngine
impl Send for SqlxEngine
impl Sync for SqlxEngine
impl Unpin for SqlxEngine
impl !UnwindSafe 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
Mutably borrows from an owned value. Read more
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>
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 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>
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 moreSource§impl<T> ProcedureEngine for Twhere
T: QueryEngine + Clone + 'static,
impl<T> ProcedureEngine for Twhere
T: QueryEngine + Clone + 'static,
Source§fn execute_procedure(
&self,
call: ProcedureCall,
) -> Pin<Box<dyn Future<Output = Result<ProcedureResult, QueryError>> + Send + '_>>where
Self: Clone + 'static,
fn execute_procedure(
&self,
call: ProcedureCall,
) -> Pin<Box<dyn Future<Output = Result<ProcedureResult, QueryError>> + Send + '_>>where
Self: Clone + 'static,
Execute a procedure call.