}
pub async fn add_name(
&self,
name: String,
) -> Result<i64, Box<dyn std::error::Error>> {
match self
.post(move |conn| {
let mut stmnt =
conn.prepare("INSERT INTO names(name) VALUES(?)")?;
stmnt.bind::<&str>(1, name.borrow())?;
stmnt.next().ok();
let mut stmnt = conn
.prepare("SELECT rowid FROM names WHERE names.name = ?")?;
stmnt.bind::<&str>(1, name.borrow())?;
match stmnt.next()? {
sqlite::State::Row => Ok(stmnt.read::<i64>(0)?),
_ => Err(sqlite::Error {
code: None,
message: Some(String::from(
"Expected rowid from row just inserted",
)),
}),
}
})
.await
{
Err(e) => Err(e),
Ok(Err(e)) => Err(Box::new(e) as Box<dyn std::error::Error>),
Ok(Ok(r)) => Ok(r),
}