https://github.com/cfsamson/macros_sql_crud
https://github.com/cfsamson/macros_sql_crud
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/cfsamson/macros_sql_crud
- Owner: cfsamson
- Created: 2020-02-15T11:44:06.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-02-15T23:31:16.000Z (over 5 years ago)
- Last Synced: 2025-02-09T22:24:53.210Z (4 months ago)
- Language: Rust
- Size: 8.79 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sql Procedural Macro
Proc macro for creating verbose sql statements from structs
## Usage
```rust
#[derive(Sql, Debug)]
struct T {
#[id]
id: i32,
name: String,
};assert_eq!(T::create_sql("persons", "$"), "INSERT INTO persons (id, name) VALUES ($1,$2);");
assert_eq!(T::update_sql("persons", "$"), "UPDATE persons SET (id = $1, name = $2);");
assert_eq!(T::delete_sql("persons", "$"), "DELETE FROM persons WHERE id = $1;");
assert_eq!(T::get_by_id_sql("persons", "$"), "SELECT id, name FROM persons WHERE id = $1;");
```Deriving `Sql` adds two methods to the struct: `create_sql` and `update_sql`.
The parameters `tbl_name` is the name of the table you want to generate for,
`param_prefix` is the prefix for parameters for the database provider you use
i.e. "$" for postgres or "@P" for mssql.