Skip to main content

Composer

Struct Composer 

Source
pub struct Composer {
    pub dialect: Dialect,
    pub search_paths: Vec<PathBuf>,
    pub mock_tables: HashMap<String, MockTable>,
}
Expand description

Composes parsed templates into final SQL.

Handles dialect-specific placeholder generation, compose reference resolution, and mock table substitution.

Fields§

§dialect: Dialect

The target database dialect for placeholder syntax.

§search_paths: Vec<PathBuf>

Directories to search for template files referenced by :compose().

§mock_tables: HashMap<String, MockTable>

Mock tables for test data substitution.

Implementations§

Source§

impl Composer

Source

pub fn new(dialect: Dialect) -> Self

Create a new composer with the given dialect.

Source

pub fn add_search_path(&mut self, path: PathBuf)

Add a search path for resolving compose references.

Source

pub fn add_mock_table(&mut self, mock: MockTable)

Register a mock table for test data substitution.

Source

pub fn compose(&self, template: &Template) -> Result<ComposedSql>

Compose a template into final SQL with placeholders.

Source

pub fn compose_with_values<V>( &self, template: &Template, values: &BTreeMap<String, Vec<V>>, ) -> Result<ComposedSql>

Compose a template with value counts, expanding multi-value bindings into multiple placeholders.

When a :bind(name) has multiple values in the map, this method emits one placeholder per value (e.g. $1, $2, $3 for 3 values), and repeats the bind name in bind_params for each. This enables IN clauses:

SELECT * FROM users WHERE id IN (:bind(ids))
-- with ids=[10, 20, 30] becomes:
SELECT * FROM users WHERE id IN ($1, $2, $3)
-- bind_params = ["ids", "ids", "ids"]

For bindings with only one value, behavior is identical to Composer::compose().

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.