Macro bsql

Source
macro_rules! bsql {
    {@ [
        $str:literal
    $($rest:tt)* ] $($out:tt)* } => { ... };
    {@ [
        ( $param:expr )
    $($rest:tt)* ] $($out:tt)* } => { ... };
    {@ [
        $param:ident
    $($rest:tt)* ] $($out:tt)* } => { ... };
    {@ [
        +~( $row:expr )
    $($rest:tt)* ] $($out:tt)* } => { ... };
    {@ [
        +*( $param:expr )
    $($rest:tt)* ] $($out:tt)* } => { ... };
    {@ [
        [ $($param:expr),* $(,)? ]
    $($rest:tt)* ] $($out:tt)* } => { ... };
    {@ [ ] $($out:tt)* } => { ... };
    {@ [ $wrong:tt $($rest:tt)* ] $($out:tt)* } => { ... };
    {$( $input:tt )* } => { ... };
}
Expand description

Generates a BoundSql.

Input contains the following pieces:

  • “string literal”: Plain literal sql text.

  • (expression): If expression is ToSql + Sync, adds it as a bind parameter, and adds " ? " to the sql query text.

    Or, expression can be BoundSql. Its sql text appears here, and its bind parameters are also added.

  • identifier: Abbreviated syntax for (identifier).

  • [ expression, expression, … ]: Bind parameters comma separated in the SQL text. Every expression must have the same type (they’re made into a slice). The expansion in the sql text is " ?,? " with an appropriate number of ?. Useful with conditions like "VALUE IN (...)".

  • +~(expression) +*(expression): A row for an INSERT. expression must implement AsSqlRow. Expands to (c0,c1,..) VALUES (?,?,..) with bindings for the columns c0, c1, etc., in expression. With +~, skips rowid columns (marked #[deftly(bsql(rowid))]); with +*, includes them.