OxL Справочник OxL
РусскийEnglish

method Db.upsert

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

Example:

oxl✓ проверяется в 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)}")
}
Вывод
b 1
pub(api) fn upsert<T>(x: &T) db

С версии. 1.0.0-beta

Параметры

ИмяТип
x&T

Эффекты

db

Определено в: std/orm/orm.oxl:372

См. также