pub struct SqliteEngine { /* private fields */ }Expand description
SQLite query engine.
Implementations§
Source§impl SqliteEngine
impl SqliteEngine
Sourcepub fn new(pool: SqlitePool) -> Self
pub fn new(pool: SqlitePool) -> Self
Create a new SQLite engine with the given pool.
Sourcepub fn pool(&self) -> &SqlitePool
pub fn pool(&self) -> &SqlitePool
Get a reference to the connection pool.
Sourcepub async fn query_many(
&self,
table: &str,
columns: &[String],
filters: &HashMap<String, FilterValue>,
sort: &[(String, SortOrder)],
limit: Option<u64>,
offset: Option<u64>,
) -> Result<Vec<SqliteQueryResult>, SqliteError>
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<SqliteQueryResult>, SqliteError>
Execute a query and return multiple results.
Sourcepub async fn query_one(
&self,
table: &str,
columns: &[String],
filters: &HashMap<String, FilterValue>,
) -> Result<SqliteQueryResult, SqliteError>
pub async fn query_one( &self, table: &str, columns: &[String], filters: &HashMap<String, FilterValue>, ) -> Result<SqliteQueryResult, SqliteError>
Execute a query and return a single result.
Sourcepub async fn query_optional(
&self,
table: &str,
columns: &[String],
filters: &HashMap<String, FilterValue>,
) -> Result<Option<SqliteQueryResult>, SqliteError>
pub async fn query_optional( &self, table: &str, columns: &[String], filters: &HashMap<String, FilterValue>, ) -> Result<Option<SqliteQueryResult>, SqliteError>
Execute a query and return an optional result.
Sourcepub async fn execute_insert(
&self,
table: &str,
data: &HashMap<String, FilterValue>,
) -> Result<SqliteQueryResult, SqliteError>
pub async fn execute_insert( &self, table: &str, data: &HashMap<String, FilterValue>, ) -> Result<SqliteQueryResult, SqliteError>
Execute an INSERT and return the result.
Sourcepub async fn execute_update(
&self,
table: &str,
data: &HashMap<String, FilterValue>,
filters: &HashMap<String, FilterValue>,
) -> Result<u64, SqliteError>
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.
Sourcepub async fn execute_delete(
&self,
table: &str,
filters: &HashMap<String, FilterValue>,
) -> Result<u64, SqliteError>
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.
Sourcepub async fn execute_raw(
&self,
sql: &str,
params: &[FilterValue],
) -> Result<Vec<SqliteQueryResult>, SqliteError>
pub async fn execute_raw( &self, sql: &str, params: &[FilterValue], ) -> Result<Vec<SqliteQueryResult>, SqliteError>
Execute raw SQL and return results.
Sourcepub async fn raw_sql(
&self,
sql: Sql,
) -> Result<Vec<SqliteQueryResult>, SqliteError>
pub async fn raw_sql( &self, sql: Sql, ) -> Result<Vec<SqliteQueryResult>, SqliteError>
Sourcepub async fn raw_sql_query(
&self,
sql: &str,
params: &[FilterValue],
) -> Result<Vec<SqliteQueryResult>, SqliteError>
pub async fn raw_sql_query( &self, sql: &str, params: &[FilterValue], ) -> Result<Vec<SqliteQueryResult>, SqliteError>
Sourcepub async fn raw_sql_execute(
&self,
sql: &str,
params: &[FilterValue],
) -> Result<u64, SqliteError>
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);Sourcepub async fn raw_sql_first(
&self,
sql: &str,
params: &[FilterValue],
) -> Result<SqliteQueryResult, SqliteError>
pub async fn raw_sql_first( &self, sql: &str, params: &[FilterValue], ) -> Result<SqliteQueryResult, SqliteError>
Sourcepub async fn raw_sql_optional(
&self,
sql: &str,
params: &[FilterValue],
) -> Result<Option<SqliteQueryResult>, SqliteError>
pub async fn raw_sql_optional( &self, sql: &str, params: &[FilterValue], ) -> Result<Option<SqliteQueryResult>, SqliteError>
Sourcepub async fn raw_sql_scalar<T>(
&self,
sql: &str,
params: &[FilterValue],
) -> Result<T, SqliteError>where
T: for<'a> Deserialize<'a>,
pub async fn raw_sql_scalar<T>(
&self,
sql: &str,
params: &[FilterValue],
) -> Result<T, SqliteError>where
T: for<'a> Deserialize<'a>,
Sourcepub async fn raw_sql_batch(&self, sql: &str) -> Result<(), SqliteError>
pub async fn raw_sql_batch(&self, sql: &str) -> Result<(), SqliteError>
Sourcepub async fn count(
&self,
table: &str,
filters: &HashMap<String, FilterValue>,
) -> Result<u64, SqliteError>
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 SqliteEngine
impl Clone for SqliteEngine
Source§fn clone(&self) -> SqliteEngine
fn clone(&self) -> SqliteEngine
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 moreAuto Trait Implementations§
impl Freeze for SqliteEngine
impl !RefUnwindSafe for SqliteEngine
impl Send for SqliteEngine
impl Sync for SqliteEngine
impl Unpin for SqliteEngine
impl !UnwindSafe for SqliteEngine
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