bsql

Macro bsql 

Source
macro_rules! bsql {
    { @ [ $builder:expr ] } => { ... };
    { @ [ $builder:expr ]     $str:literal     $($rest:tt)* } => { ... };
    { @ [ $builder:expr ]     $value:ident     $($rest:tt)* } => { ... };
    { @ [ $builder:expr ]     ($value:expr)     $($rest:tt)* } => { ... };
    { @ [ $builder:expr ]     { $fragment:expr }     $($rest:tt)* } => { ... };
    { @ [ $builder:expr ]     [ $($elem:tt)* ]     $($rest:tt)* } => { ... };
    { @ [ $builder:expr ]  .$method:ident($($params:tt)*)  $($rest:tt)* } => { ... };
    { @ [ $builder:expr ]     $($wrong:tt)+     } => { ... };
    { $($input:tt)* } => { ... };
}
Expand description

Generates an [impl Bsql].

Expands to an expression of type Builder<impl Bsql>.

Input can contain the following pieces:

  • “string literal”: Plain literal sql text.

    Equivalent to a call to [Builder.text()].

  • (value): A single bind value, impl ToSql + Sync.

    SQL text: ?

    Equivalent to a call to [Builder.value()].

  • identifier: A single bind value, in a Rust variable.

    SQL text: ?

    Abbreviated syntax for (identifier). Equivalent to a call to [Builder.value()].

  • {expression}: A SQL fragment with any associated bind values.

    Expression must be Bsql. (So &impl Bsql and &dyn Bsql are allowed.)

    Equivalent to a call to [Builder.fragment()].

  • [ ARRAY CONTENTS … ]: A Rust array as a SQL row value.

    SQL text: (?,?,...)

    The array element type must be ToSql + Sync. Useful with conditions like "VALUE IN (...)".

    Equivalent to a call to [Builder.array_as_row_value()].

  • .METHOD(ARGUMENTS): Call Builder::method. METHOD must be a method on Builder. Typically:

    • .insert_row(impl AsSqlRow)
    • .ref_iter_as_row_value(&impl Iterator<&impl ToSql + Sync>)

    Methods available via method dispatch are also allowed, including ones in extension traits in scope. METHOD’s return value should be another Builder, This is true of Builder’s inherent methods.

    Generics are not permitted and UFCS is not available. To append things other than via methods on Builder, represent them as something that implements Bsql, and put that value in { } in bsql!. To apply arbitrary transformations to the being-built Bsql, use the expansion of bsql! as an expression.