pub struct SqliteConnector { /* private fields */ }Expand description
First-class SQLite connector backed by a bundled rusqlite connection.
Construct with SqliteConnector::open (file-backed) or
SqliteConnector::open_in_memory (:memory:, ideal for tests). Implements
the full SqlConnector trait so it drops straight into the toolkit’s
synthesize_from_config_with_connector plumbing as an Arc<dyn SqlConnector>.
Implementations§
Source§impl SqliteConnector
impl SqliteConnector
Sourcepub fn open(path: &Path) -> Result<Self, ConnectorError>
pub fn open(path: &Path) -> Result<Self, ConnectorError>
Open a file-backed SQLite database at path.
§Errors
Returns ConnectorError::Connection if rusqlite cannot open the
database file. The error message comes from rusqlite and is bounded
(e.g. “unable to open database file”) — it does not echo arbitrary
caller data (T-84-04-02).
Sourcepub fn open_in_memory() -> Result<Self, ConnectorError>
pub fn open_in_memory() -> Result<Self, ConnectorError>
Open an in-memory SQLite database (:memory:).
Reusable across tests and ideal for ephemeral, schema-on-demand work:
seed a schema via SqlConnector::execute after construction.
§Errors
Returns ConnectorError::Connection if rusqlite cannot create the
in-memory database.
Sourcepub async fn execute_batch(&self, sql: &str) -> Result<(), ConnectorError>
pub async fn execute_batch(&self, sql: &str) -> Result<(), ConnectorError>
Run a multi-statement SQL batch (;-separated DDL + INSERTs) in ONE call.
SqlConnector::execute is single-statement (it prepares exactly one
statement); a schema.sql bootstrap that issues several CREATE TABLE
and INSERT statements cannot run through it. This inherent helper wraps
rusqlite::Connection::execute_batch, which executes every statement in
the batch sequentially, so a demo database can be seeded with a single
call inside the toolkit’s ≤15-line wiring.
This is an inherent method on the concrete SqliteConnector — it is
deliberately NOT part of the locked 3-method SqlConnector trait. Call
it on the concrete connector BEFORE wrapping it in
Arc<dyn SqlConnector>; an Arc<dyn SqlConnector> exposes only the trait
surface and would not resolve execute_batch.
The batch is intended for IDEMPOTENT bootstrap SQL — use
CREATE TABLE IF NOT EXISTS and INSERT OR IGNORE — so a second run
against an already-seeded persisted database is safe and leaves exactly
the seeded rows.
§Errors
Returns ConnectorError::Query if any statement in the batch fails
(e.g. a syntax error); the message is the bounded rusqlite error string
and does not echo the batch text. Returns ConnectorError::Driver if
the connection mutex is poisoned or the blocking task fails to join.
§Example
let conn = SqliteConnector::open_in_memory().unwrap();
conn.execute_batch(
"CREATE TABLE t(id INTEGER); INSERT INTO t VALUES (1); INSERT INTO t VALUES (2);",
)
.await
.unwrap();
let rows = conn.execute("SELECT COUNT(*) AS c FROM t", &[]).await.unwrap();
assert_eq!(rows[0]["c"], serde_json::json!(2));Trait Implementations§
Source§impl SqlConnector for SqliteConnector
impl SqlConnector for SqliteConnector
Source§fn dialect(&self) -> Dialect
fn dialect(&self) -> Dialect
Source§fn execute<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: &'life2 [(String, Value)],
) -> Pin<Box<dyn Future<Output = Result<Vec<Value>, ConnectorError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn execute<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: &'life2 [(String, Value)],
) -> Pin<Box<dyn Future<Output = Result<Vec<Value>, ConnectorError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
serde_json::Value per result row. Read moreSource§fn schema_text<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<String, ConnectorError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn schema_text<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<String, ConnectorError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
information_schema,
the Glue catalog, or sqlite_master per dialect. Read moreAuto Trait Implementations§
impl Freeze for SqliteConnector
impl RefUnwindSafe for SqliteConnector
impl Send for SqliteConnector
impl Sync for SqliteConnector
impl Unpin for SqliteConnector
impl UnsafeUnpin for SqliteConnector
impl UnwindSafe for SqliteConnector
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> 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