OxL Reference

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

Since. 1.0.0-beta

Parameters

NameType
x&T

Returns

()

Errors

Effects

db

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

See also