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:
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 dbSince. 1.0.0-beta
Parameters
| Name | Type |
|---|---|
x | &T |
Returns
()
Errors
DbError@error
Effects
db
Defined in: std/orm/orm.oxl:331