Skip to main content

ComposerConnection

Trait ComposerConnection 

Source
pub trait ComposerConnection {
    type Value;
    type Statement;
    type Error: From<Error>;

    // Required method
    fn compose(
        &self,
        composer: &Composer,
        template: &Template,
        values: BTreeMap<String, Vec<Self::Value>>,
    ) -> Result<(Self::Statement, Vec<Self::Value>), Self::Error>;
}
Expand description

Trait for synchronous database drivers that can compose and prepare SQL.

Each driver crate implements this for its connection type, providing the bridge between sql-composer’s template system and the database’s API.

§Example

let (sql, values) = conn.compose(&composer, &template, bind_values!("id" => [1]))?;
let mut stmt = conn.prepare(&sql)?;
let rows = stmt.query_map(params_from_iter(values.iter().map(|v| v.as_ref())), |row| { ... })?;

Required Associated Types§

Source

type Value

The database-specific value type for bind parameters.

e.g. Box<dyn rusqlite::types::ToSql> or Box<dyn duckdb::ToSql>

Source

type Statement

The composed SQL string (callers use this to prepare statements).

Source

type Error: From<Error>

The error type for this driver.

Required Methods§

Source

fn compose( &self, composer: &Composer, template: &Template, values: BTreeMap<String, Vec<Self::Value>>, ) -> Result<(Self::Statement, Vec<Self::Value>), Self::Error>

Compose a template with bind values, returning prepared SQL and ordered values.

Takes the composer, a parsed template, and a map of named bind values. Resolves bind parameter order and returns the SQL string with ordered values ready for execution.

Implementors§