Skip to main content

SqliteRawEngine

Struct SqliteRawEngine 

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

Legacy SQLite query engine with JSON results.

Implementations§

Source§

impl SqliteRawEngine

Source

pub fn new(pool: SqlitePool) -> Self

Create a new SQLite engine with the given pool.

Source

pub fn pool(&self) -> &SqlitePool

Get a reference to the connection pool.

Source

pub async fn query_many( &self, table: &str, columns: &[String], filters: &HashMap<String, FilterValue>, sort: &[(String, SortOrder)], limit: Option<u64>, offset: Option<u64>, ) -> Result<Vec<SqliteJsonRow>, SqliteError>

Execute a query and return multiple results.

Source

pub async fn query_one( &self, table: &str, columns: &[String], filters: &HashMap<String, FilterValue>, ) -> Result<SqliteJsonRow, SqliteError>

Execute a query and return a single result.

Source

pub async fn query_optional( &self, table: &str, columns: &[String], filters: &HashMap<String, FilterValue>, ) -> Result<Option<SqliteJsonRow>, SqliteError>

Execute a query and return an optional result.

Source

pub async fn execute_insert( &self, table: &str, data: &HashMap<String, FilterValue>, ) -> Result<SqliteJsonRow, SqliteError>

Execute an INSERT and return the result.

The returned row echoes the submitted values plus the rowid of the new row under the id key (skipped if an id value was submitted); it does not re-read the persisted row, so database-generated defaults and trigger effects are not reflected.

Source

pub async fn execute_update( &self, table: &str, data: &HashMap<String, FilterValue>, filters: &HashMap<String, FilterValue>, ) -> Result<u64, SqliteError>

Execute an UPDATE and return the number of affected rows.

Source

pub async fn execute_delete( &self, table: &str, filters: &HashMap<String, FilterValue>, ) -> Result<u64, SqliteError>

Execute a DELETE and return the number of affected rows.

Source

pub async fn execute_raw( &self, sql: &str, params: &[FilterValue], ) -> Result<Vec<SqliteJsonRow>, SqliteError>

Execute raw SQL and return results.

Source

pub async fn raw_sql(&self, sql: Sql) -> Result<Vec<SqliteJsonRow>, SqliteError>

Execute a raw SQL query using the Sql builder from prax-query.

§Example
use prax_query::raw::Sql;

let sql = Sql::new("SELECT * FROM users WHERE age > ")
    .bind(18)
    .push(" AND active = ")
    .bind(true);

let results = engine.raw_sql(sql).await?;
Source

pub async fn raw_sql_query( &self, sql: &str, params: &[FilterValue], ) -> Result<Vec<SqliteJsonRow>, SqliteError>

Execute a raw SQL query string with parameters and return results.

§Example
let results = engine.raw_sql_query(
    "SELECT * FROM users WHERE age > ? AND active = ?",
    &[FilterValue::Int(18), FilterValue::Bool(true)]
).await?;
Source

pub async fn raw_sql_execute( &self, sql: &str, params: &[FilterValue], ) -> Result<u64, SqliteError>

Execute a raw SQL statement and return the number of affected rows.

Use this for INSERT, UPDATE, DELETE, or other statements that don’t return rows.

§Example
let affected = engine.raw_sql_execute(
    "UPDATE users SET last_login = datetime('now') WHERE id = ?",
    &[FilterValue::Int(user_id)]
).await?;
println!("Updated {} rows", affected);
Source

pub async fn raw_sql_first( &self, sql: &str, params: &[FilterValue], ) -> Result<SqliteJsonRow, SqliteError>

Execute a raw SQL query and return the first result.

Returns an error if no rows are returned.

§Example
let user = engine.raw_sql_first(
    "SELECT * FROM users WHERE id = ?",
    &[FilterValue::Int(user_id)]
).await?;
Source

pub async fn raw_sql_optional( &self, sql: &str, params: &[FilterValue], ) -> Result<Option<SqliteJsonRow>, SqliteError>

Execute a raw SQL query and return the first result, or None if no rows.

§Example
let user = engine.raw_sql_optional(
    "SELECT * FROM users WHERE email = ?",
    &[FilterValue::String("test@example.com".into())]
).await?;
Source

pub async fn raw_sql_scalar<T>( &self, sql: &str, params: &[FilterValue], ) -> Result<T, SqliteError>
where T: for<'a> Deserialize<'a>,

Execute a raw SQL query and return a single scalar value.

§Example
let count: i64 = engine.raw_sql_scalar(
    "SELECT COUNT(*) FROM users WHERE active = ?",
    &[FilterValue::Bool(true)]
).await?;
Source

pub async fn raw_sql_batch(&self, sql: &str) -> Result<(), SqliteError>

Execute multiple raw SQL statements in a batch.

This is useful for running schema migrations or multiple DDL statements.

§Example
engine.raw_sql_batch(r#"
    CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY);
    CREATE TABLE IF NOT EXISTS posts (id INTEGER PRIMARY KEY);
"#).await?;
Source

pub async fn count( &self, table: &str, filters: &HashMap<String, FilterValue>, ) -> Result<u64, SqliteError>

Count rows matching the filter.

Trait Implementations§

Source§

impl Clone for SqliteRawEngine

Source§

fn clone(&self) -> SqliteRawEngine

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

Auto Trait Implementations§

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<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> 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> 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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<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