Exchange DB changes over Iroh

This commit is contained in:
Eric Wendland 2026-05-18 22:11:57 +02:00
commit 20fd773a42
10 changed files with 563 additions and 15 deletions

View file

@ -309,6 +309,26 @@ impl Store {
}
}
pub fn list_db_resources(&self) -> Result<Vec<StoredDbResource>, StoreError> {
let mut stmt = self.conn.prepare(
r#"SELECT db.db_id, db.resource_id, resources.name, db.path
FROM db_resources db
JOIN resources ON resources.resource_id = db.resource_id
WHERE resources.kind = 'db'
ORDER BY resources.name"#,
)?;
let rows = stmt.query_map([], |row| {
Ok(StoredDbResource {
db_id: row.get(0)?,
resource_id: row.get(1)?,
name: row.get(2)?,
path: row.get(3)?,
})
})?;
rows.collect::<Result<Vec<_>, _>>()
.map_err(StoreError::from)
}
pub fn insert_kv_store(&self, kv: &StoredKvStore) -> Result<(), StoreError> {
self.conn.execute(
r#"INSERT OR REPLACE INTO kv_stores(kv_id, resource_id, name)
@ -1479,6 +1499,15 @@ mod tests {
.map(|db| db.path),
Some("/tmp/notes.sqlite".to_owned())
);
assert_eq!(
store
.list_db_resources()
.expect("list db resources")
.into_iter()
.map(|db| db.name)
.collect::<Vec<_>>(),
vec!["notes".to_owned()]
);
}
#[test]