#[tokio::main]
async fn main() {
let db = libsql::Builder::new_local(":memory:")
.build()
.await
.unwrap();
let c = db.connect().unwrap();
c.execute("CREATE TABLE t (a TEXT)", ()).await.unwrap();
c.execute(
"CREATE TRIGGER trg BEFORE INSERT ON t WHEN NEW.a = 'no' \
BEGIN SELECT RAISE(ABORT, 'macrame: the guard fired'); END",
(),
)
.await
.unwrap();
let e = c
.execute("INSERT INTO t (a) VALUES ('no')", ())
.await
.unwrap_err();
println!("RAISE(ABORT)");
println!(" Display : {e}");
println!(" Debug : {e:?}");
match &e {
libsql::Error::SqliteFailure(code, msg) => {
println!(" variant : SqliteFailure");
println!(" code : {code}");
println!(" msg : {msg:?}");
}
other => println!(" variant : {other:?} (not SqliteFailure)"),
}
c.execute("CREATE TABLE u (a TEXT NOT NULL)", ())
.await
.unwrap();
let e2 = c
.execute("INSERT INTO u (a) VALUES (NULL)", ())
.await
.unwrap_err();
println!();
println!("NOT NULL");
println!(" Display : {e2}");
if let libsql::Error::SqliteFailure(code, msg) = &e2 {
println!(" code : {code}");
println!(" msg : {msg:?}");
}
}