trevyn / turbosql

An easy local data persistence layer for Rust, backed by SQLite.
204 stars 8 forks source link

Add `.upsert()` impl #18

Open trevyn opened 3 years ago

trevyn commented 3 years ago

With SQLite INSERT OR REPLACE INTO

or

execute!(
    "INSERT INTO node(host, id)"
    "VALUES (" host, node.id ")"
    "ON CONFLICT(host) DO UPDATE SET id = " node.id
)?;
Node {
    host: Some(host),
    id: Some(node.id),
    ..Default::default()
}.upsert_on("host")?;
upsert!(Node { host, id: node.id });
insert!(Node { host, id: node.id });

Oh dear.