pub struct InMemorySqlEngine { /* private fields */ }Expand description
The in-memory SQLite engine.
Implementations§
Source§impl InMemorySqlEngine
impl InMemorySqlEngine
pub fn open() -> Result<Self, SqlQueryError>
Sourcepub fn interrupt_handle(&self) -> InterruptHandle
pub fn interrupt_handle(&self) -> InterruptHandle
Returns an interrupt handle that can cancel a running statement from another thread (used by the request-level timeout watchdog).
Sourcepub fn create_table(
&self,
label: &str,
schema: &TableSchema,
) -> Result<(), SqlQueryError>
pub fn create_table( &self, label: &str, schema: &TableSchema, ) -> Result<(), SqlQueryError>
Create a table with the given label and schema.
Sourcepub fn create_view(
&self,
label: &str,
source: &str,
) -> Result<(), SqlQueryError>
pub fn create_view( &self, label: &str, source: &str, ) -> Result<(), SqlQueryError>
Creates a view named label that exposes every row and column of
the existing table (or view) source, so a consumer’s SQL can address
that table under a second name without copying a single row. Both
identifiers go through the same validation as Self::create_table.
The view lives in this request’s in-memory database and disappears
with it.
Sourcepub async fn insert_rows<S>(
self,
label: &str,
schema: &TableSchema,
rows: Pin<Box<S>>,
max_rows: usize,
) -> Result<(Self, usize), SqlQueryError>
pub async fn insert_rows<S>( self, label: &str, schema: &TableSchema, rows: Pin<Box<S>>, max_rows: usize, ) -> Result<(Self, usize), SqlQueryError>
Streams rows into label on a dedicated blocking thread, then
hands the engine back to the caller.
The engine (and the rusqlite::Statement the insert loop prepares)
is not Send across an .await point, and the row stream is
typically a tokio::sync::mpsc channel whose recv spends the
polling task’s cooperative budget on every item — draining more than
128 rows in an ordinary async task therefore starves the waker and
hangs forever. Moving the whole operation into
tokio::task::spawn_blocking sidesteps both problems: the engine
crosses into a blocking-pool thread by value, the stream is driven
with Handle::block_on (which resets the cooperative budget on every
poll and is safe to use exactly because there is no scheduler to
starve on that thread), and the engine is returned to the caller once
the whole insert has completed.
Returns Ok((engine, n)) on success, where n is the number of rows
inserted and the transaction has been committed. On Err, the
transaction has already been rolled back and the engine is dropped;
callers are expected to abort the current plan rather than keep using
a half-populated database.
Sourcepub fn execute_select(
&self,
sql: &str,
bindings: &[BoundParam],
max_rows: usize,
) -> Result<QueryResult, SqlQueryError>
pub fn execute_select( &self, sql: &str, bindings: &[BoundParam], max_rows: usize, ) -> Result<QueryResult, SqlQueryError>
Run a SELECT with named bindings and a row cap.
Auto Trait Implementations§
impl !Freeze for InMemorySqlEngine
impl !RefUnwindSafe for InMemorySqlEngine
impl !Sync for InMemorySqlEngine
impl !UnwindSafe for InMemorySqlEngine
impl Send for InMemorySqlEngine
impl Unpin for InMemorySqlEngine
impl UnsafeUnpin for InMemorySqlEngine
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