[][src]Module toql_core::indelup

Insert / Delete / Update

The database support of the Toql derive can build functions to insert, delete and update structs.

Example (Read the guide for derive attributes)

This example is not tested
#[derive(Debug, PartialEq, Toql)]
struct NewUser {
    id: u8, // Auto value, no insert
    username: Option<String>,
let u = NewUser {
            id: 5,
            username: Some(String::from("Foo")),

let (sql, params) = NewUser::insert_one_sql(&u).unwrap();

assert_eq!("INSERT INTO NewUser (username) VALUES (?)", sql);
assert_eq!(["Foo"], *params);

Note that operations are not cascaded. If you insert a struct Foo that contains another struct Bar only `Foo will be inserted. To deal with those dependencies, you are expected to make multiple calls.

If you update a struct, fields of type Option<> with value None are skipped. Read the guide for details!



Trait for insert delete and update functions.