typed-sql
typed-sql copied to clipboard
Add `RETURNING` clause support.
To insert the increasing IDs can be useful to be able to get the result of the insertion.
This is a very crude example, but I would like to have an interface similar to:
#[derive(Default, Debug, typed_sql::Table)]
struct SomeStruct {
// It can be represent like NULL if it None.
// ..or it can just be ignored.
id: Option<u64>,
some_useful_data: u128,
}
let insert = SomeStruct::table()
.insert(SomeStruct::default())
.returns(|some_struct| some_struct.id)
.to_sql();
assert_eq!(
insert,
"INSERT into somestruct(some_useful_data) VALUES (0) RETURNING id;"
);