method Table.upsert
Inserts the row, or replaces the row with the same primary key.
Example:
use std.orm { Db }
@table("items")
data Item {
@pk id: i64
name: str
price: i64
}
fn main() io, db {
let db = Db.open("sqlite::memory:")!
db.Item.upsert(Item{ id: 1, name: "tea", price: 3 })
db.Item.upsert(Item{ id: 1, name: "green tea", price: 4 })
print("{db.Item.count()} {db.Item.all()[0].name}")
db.close()
}Output
1 green tea
pub(api) fn upsert(x: &T) dbSince. 1.0.0-beta
Parameters
| Name | Type |
|---|---|
x | &T |
Effects
db
Defined in: std/orm/orm.oxl:1062