Skip to main content

SqlReader

Trait SqlReader 

Source
pub trait SqlReader: Send + 'static {
    // Required methods
    fn query_row<'life0, 'async_trait>(
        &'life0 mut self,
        statement: SqlStatement,
    ) -> Pin<Box<dyn Future<Output = StorageResult<Option<SqlRow>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn query_all<'life0, 'async_trait>(
        &'life0 mut self,
        statement: SqlStatement,
    ) -> Pin<Box<dyn Future<Output = StorageResult<Vec<SqlRow>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn query_scalar<'life0, 'async_trait>(
        &'life0 mut self,
        statement: SqlStatement,
    ) -> Pin<Box<dyn Future<Output = StorageResult<Option<SqlValue>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn explain<'life0, 'async_trait>(
        &'life0 mut self,
        statement: SqlStatement,
    ) -> Pin<Box<dyn Future<Output = StorageResult<Vec<SqlRow>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    fn query_page<'life0, 'async_trait>(
        &'life0 mut self,
        statement: SqlStatement,
        page: PageRequest,
    ) -> Pin<Box<dyn Future<Output = StorageResult<Vec<SqlRow>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Read-capable SQL connection.

Required Methods§

Source

fn query_row<'life0, 'async_trait>( &'life0 mut self, statement: SqlStatement, ) -> Pin<Box<dyn Future<Output = StorageResult<Option<SqlRow>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute statement and return the first row, or None if the result set is empty. Implementations must not convert later matching rows into owned values. Implementations may stop stepping the statement early, so statements with side effects (e.g. DML with RETURNING) must not be issued through this method; use SqlWriter::execute or SqlWriter::execute_batch for writes.

Source

fn query_all<'life0, 'async_trait>( &'life0 mut self, statement: SqlStatement, ) -> Pin<Box<dyn Future<Output = StorageResult<Vec<SqlRow>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute statement and return all rows.

This compatibility primitive has no result-size bound. Callers that do not already constrain their SQL should use Self::query_page.

Source

fn query_scalar<'life0, 'async_trait>( &'life0 mut self, statement: SqlStatement, ) -> Pin<Box<dyn Future<Output = StorageResult<Option<SqlValue>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute statement and return the first column of the first row as a scalar.

Source

fn explain<'life0, 'async_trait>( &'life0 mut self, statement: SqlStatement, ) -> Pin<Box<dyn Future<Output = StorageResult<Vec<SqlRow>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Run EXPLAIN QUERY PLAN for statement and return the plan rows.

Provided Methods§

Source

fn query_page<'life0, 'async_trait>( &'life0 mut self, statement: SqlStatement, page: PageRequest, ) -> Pin<Box<dyn Future<Output = StorageResult<Vec<SqlRow>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute statement and return only the requested offset page.

The default preserves source compatibility for alternate backends by slicing Self::query_all. Backends should override this method when they can stop row conversion at page.limit; khive-db’s SQLite bridge does so. On that path, materialization is bounded by the caller-supplied page.limit, and callers own choosing a sane limit; the database engine may still do work for the query plan and offset.

Like Self::query_all, the default has no result-size bound: it materializes every matching row before slicing. Callers issuing unconstrained SQL must not rely on the default to keep memory proportional to page.limit — that bound holds only on backends that override this method.

Implementations may stop stepping the statement early, so statements with side effects (e.g. DML with RETURNING) must not be issued through this method; use SqlWriter::execute or SqlWriter::execute_batch for writes.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§