#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ExportRecord {
pub key: Vec<u8>,
pub value: Option<Vec<u8>>,
}
#[derive(Debug, Clone)]
pub struct VacuumStats {
pub xmin: u64,
pub versions_removed: usize,
pub blob_rewritten: Option<bool>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ValueMeta {
Plain { user: Vec<u8> },
Ttl { expire_unix_secs: u64, user: Vec<u8> },
}
impl ValueMeta {
pub fn user(&self) -> &[u8] {
match self {
ValueMeta::Plain { user } => user,
ValueMeta::Ttl { user, .. } => user,
}
}
pub fn expire_unix_secs(&self) -> Option<u64> {
match self {
ValueMeta::Plain { .. } => None,
ValueMeta::Ttl {
expire_unix_secs, ..
} => Some(*expire_unix_secs),
}
}
pub fn is_expired_at(&self, now: u64) -> bool {
match self.expire_unix_secs() {
Some(e) => now >= e,
None => false,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct KeyMeta {
pub key: Vec<u8>,
pub value_len: Option<usize>,
pub version: u64,
pub expire_unix_secs: Option<u64>,
pub expired: bool,
pub deleted: bool,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum IncrError {
NotInteger,
Overflow,
WriteConflict,
}
impl std::fmt::Display for IncrError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
IncrError::NotInteger => write!(f, "value is not a decimal integer"),
IncrError::Overflow => write!(f, "i64 overflow"),
IncrError::WriteConflict => write!(f, "write conflict"),
}
}
}
impl std::error::Error for IncrError {}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum KeyMatchMode {
#[default]
Contains,
Prefix,
}
#[derive(Debug, Clone)]
pub struct SearchQuery {
pub pattern: Vec<u8>,
pub page: usize,
pub page_size: usize,
pub mode: KeyMatchMode,
pub include_deleted: bool,
}
impl SearchQuery {
pub fn contains(pattern: impl Into<Vec<u8>>, page: usize, page_size: usize) -> Self {
Self {
pattern: pattern.into(),
page,
page_size,
mode: KeyMatchMode::Contains,
include_deleted: false,
}
}
pub fn prefix(pattern: impl Into<Vec<u8>>, page: usize, page_size: usize) -> Self {
Self {
pattern: pattern.into(),
page,
page_size,
mode: KeyMatchMode::Prefix,
include_deleted: false,
}
}
pub fn with_deleted(mut self, include: bool) -> Self {
self.include_deleted = include;
self
}
}
#[derive(Debug, Clone)]
pub struct SearchPage {
pub items: Vec<ExportRecord>,
pub total: usize,
pub page: usize,
pub page_size: usize,
pub total_pages: usize,
}
impl SearchPage {
pub fn has_next(&self) -> bool {
self.total_pages > 0 && self.page + 1 < self.total_pages
}
pub fn has_prev(&self) -> bool {
self.page > 0 && self.total > 0
}
}