2019-10-18 19:05:28 +08:00
|
|
|
use super::BEU64;
|
|
|
|
use crate::update::UpdateResult;
|
2019-10-16 23:05:24 +08:00
|
|
|
use zlmdb::types::{OwnedType, Serde};
|
|
|
|
use zlmdb::Result as ZResult;
|
2019-10-03 22:13:09 +08:00
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
pub struct UpdatesResults {
|
2019-10-16 23:05:24 +08:00
|
|
|
pub(crate) updates_results: zlmdb::Database<OwnedType<BEU64>, Serde<UpdateResult>>,
|
2019-10-03 22:13:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl UpdatesResults {
|
2019-10-16 23:05:24 +08:00
|
|
|
pub fn last_update_id(&self, reader: &zlmdb::RoTxn) -> ZResult<Option<(u64, UpdateResult)>> {
|
|
|
|
match self.updates_results.last(reader)? {
|
|
|
|
Some((key, data)) => Ok(Some((key.get(), data))),
|
|
|
|
None => Ok(None),
|
2019-10-07 22:16:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-03 22:13:09 +08:00
|
|
|
pub fn put_update_result(
|
|
|
|
&self,
|
2019-10-16 23:05:24 +08:00
|
|
|
writer: &mut zlmdb::RwTxn,
|
2019-10-03 22:13:09 +08:00
|
|
|
update_id: u64,
|
|
|
|
update_result: &UpdateResult,
|
2019-10-18 19:05:28 +08:00
|
|
|
) -> ZResult<()> {
|
2019-10-16 23:05:24 +08:00
|
|
|
let update_id = BEU64::new(update_id);
|
|
|
|
self.updates_results.put(writer, &update_id, update_result)
|
2019-10-03 22:13:09 +08:00
|
|
|
}
|
|
|
|
|
2019-10-04 16:21:09 +08:00
|
|
|
pub fn update_result(
|
2019-10-03 22:54:37 +08:00
|
|
|
&self,
|
2019-10-16 23:05:24 +08:00
|
|
|
reader: &zlmdb::RoTxn,
|
2019-10-03 22:13:09 +08:00
|
|
|
update_id: u64,
|
2019-10-18 19:05:28 +08:00
|
|
|
) -> ZResult<Option<UpdateResult>> {
|
2019-10-16 23:05:24 +08:00
|
|
|
let update_id = BEU64::new(update_id);
|
|
|
|
self.updates_results.get(reader, &update_id)
|
2019-10-03 22:13:09 +08:00
|
|
|
}
|
|
|
|
}
|