mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-08-23 20:04:05 +02:00
25 lines
654 B
Rust
25 lines
654 B
Rust
use crate::pool::SqliteConn;
|
|
use rusqlite::{Connection, Statement, ToSql, Transaction};
|
|
|
|
pub enum ConnectionOrTx<'a> {
|
|
Connection(SqliteConn),
|
|
Transaction(&'a Transaction<'a>),
|
|
}
|
|
|
|
impl<'a> ConnectionOrTx<'a> {
|
|
pub fn resolve(&self) -> &Connection {
|
|
match self {
|
|
ConnectionOrTx::Connection(c) => c,
|
|
ConnectionOrTx::Transaction(c) => c,
|
|
}
|
|
}
|
|
|
|
pub fn prepare(&self, sql: &str) -> rusqlite::Result<Statement<'_>> {
|
|
self.resolve().prepare(sql)
|
|
}
|
|
|
|
pub fn execute(&self, sql: &str, params: &[&dyn ToSql]) -> rusqlite::Result<usize> {
|
|
self.resolve().execute(sql, params)
|
|
}
|
|
}
|