1pub mod channel;
2pub mod compression;
3pub mod consume;
4pub mod disk;
5pub mod exclusive;
6pub mod header;
7pub mod proto;
8#[cfg(unix)]
9pub mod unix;
10
11pub use self::channel::{DatabaseServer, DatabaseServerClient};
12pub use self::disk::{AccessMode, Database};
13pub use self::proto::DatabaseHandle;
14
15use crate::errors::*;
16use crate::signed::Signed;
17use crate::sync;
18use async_trait::async_trait;
19use sequoia_openpgp::Fingerprint;
20
21pub type Key = Vec<u8>;
22pub type Value = Vec<u8>;
23
24#[async_trait]
25pub trait DatabaseClient {
26 async fn add_release(&mut self, fp: &Fingerprint, signed: &Signed) -> Result<String>;
27
28 async fn index_from_scan(&mut self, query: &sync::TreeQuery) -> Result<(String, usize)>;
29
30 async fn batch_index_from_scan(
31 &mut self,
32 query: &mut sync::TreeQuery,
33 ) -> Result<(sync::BatchIndex, usize)> {
34 let mut batch = sync::BatchIndex::new();
35 let mut total = 0;
36
37 query.enter();
38 loop {
39 let (index, count) = self.index_from_scan(query).await?;
40 let prefix = query.prefix.as_deref().unwrap_or("");
41
42 trace!(
43 "Calculated index for prefix: index={index:?}, prefix={:?}, count={count:?}",
44 prefix
45 );
46
47 batch.add(index, prefix.to_string(), count)?;
49 total += count;
50
51 if query.increment() {
52 break;
53 }
54 }
55
56 Ok((batch, total))
57 }
58
59 async fn spill(&self, prefix: &[u8]) -> Result<Vec<(Key, Value)>>;
62
63 async fn get_value(&self, key: &[u8]) -> Result<Value>;
64
65 async fn count(&mut self, prefix: &[u8]) -> Result<u64>;
66}