sqler - beta
A procedural macro that helps with writing SQL queries using some of Rust syntax
Usage
First, in your Cargo.toml file add the following:
[]
= "0.0.1-beta"
Example 1
To just embedding a value of a varible you can just do the following:
use sql;
This macro will handle the process of embedding value of any variable (only built-in types) in addition to converting the Rust syntax to string that contains SQL statement.
Example 2
Also you can write the value directly:
use sql;
Example 3
You can also use hexadecimal, octal, or binary number format and the macro will handle it by converting the value back to decimal.
use sql;
Example 4
What about variable of a custom type? variable of a custom type can be embedded by first implementing the "VarToSql" trait (which tells the macro how to embed the value of that type) as follows:
use ;
;
Notes
There are a few points you should consider when using this crate:
-
Delimited Identifier - or quoted identifier is not supported. For example:
SELECT "first_name"the column namefirst_namewill be converted to a string (string is wrapped with single quote) as follows:SELECT 'first_name'. -
Variables Of Custom Type - to use variables of a custom type the
VarToSqltrait should be implemented for this type.