OxL Reference

method Db.upsert

Inserts the row or replaces the row with the same primary key.

Example:

oxl✓ checked in CI
use std.orm { Db }

@table("items")
data Item { @pk id: i64; name: str }

fn main() io, db {
  let db = Db.open("sqlite::memory:")!
  db.upsert(Item{ id: 1, name: "a" })
  db.upsert(Item{ id: 1, name: "b" })
  print("{db.find(Item, 1)!.name} {db.count(Item)}")
}
Output
b 1
pub(api) fn upsert<T>(x: &T) db

Since. 1.0.0-beta

Parameters

NameType
x&T

Effects

db

Defined in: std/orm/orm.oxl:372

See also