use rusqlite::{params, OptionalExtension}; use crate::db::*; use crate::error::{Error, Result}; // -------------------------------------------------------------------- repo -- pub fn ensure_repo(writer: &Writer, name: &str, path: &str, arch: &str, key: &str) -> Result { let (n, p, a, k) = (name.to_string(), path.to_string(), arch.to_string(), key.to_string()); writer.tx(move |tx| { tx.execute( "INSERT INTO repo (name, path, arch, signing_key_id) VALUES (?1,?2,?3,?4) ON CONFLICT(name) DO UPDATE SET path=excluded.path, arch=excluded.arch, signing_key_id=excluded.signing_key_id", params![n, p, a, k], )?; let id: i64 = tx.query_row("SELECT id FROM repo WHERE name = ?1", params![n], |r| r.get(0))?; Ok(id) }) } pub fn repo_id(db: &Db) -> Result { db.read(|c| { c.query_row("SELECT id FROM repo ORDER BY id LIMIT 1", [], |r| r.get(0)) .optional()? .ok_or_else(|| Error::not_found("no repo row; run `aur-build init`")) }) }