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

method Db.tryInsert

Inserts a row. tryInsert returns Conflict for a duplicate key or a violated unique index. Outside atomic(db) a write (insert, upsert, update, delete) that failed without changing anything (a builtin:// leader change, a busy database) is run again with the retry policy of atomic(db) (D-7300); Busy / TxConflict after it.

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.tryInsert(Item{ id: 1, name: "a" })!
  print("{db.tryInsert(Item{ id: 1, name: "b" }) is DbError}")
}
Вывод
true
pub(api) fn tryInsert<T>(x: &T) -> () | DbError  db

С версии. 1.0.0-beta

Параметры

ИмяТип
x&T

Возвращает

()

Ошибки

Эффекты

db

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

См. также