Skip to main content

insert_sql

Macro insert_sql 

Source
macro_rules! insert_sql {
    ($table:ident { $first_field:ident $(, $($field:ident),+)? $(,)? } $(| $on_conflict:expr)?) => { ... };
}
Expand description

Generates a simple insert SQL statement with parameters for the provided table name and fields. Supports optional conflict resolution (adding “| REPLACE” or “| IGNORE” at the end will generate “OR REPLACE” and “OR IGNORE”, correspondingly).

§Usage:

insert_sql!(users { id, first_name, last_name, age } | REPLACE);

which generates:

INSERT OR REPLACE INTO `users` (`id`, `first_name`, `last_name`, `age`) VALUES (?, ?, ?, ?)