1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
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<i64> {
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<i64> {
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`"))
})
}
|