use super::{
NativeRecordFamily as Family, NativeRecordIdentity, NativeRecordOwner, NativeSnapshot,
};
use crate::connection::Result;
use rusqlite::types::ValueRef;
use uqa_storage::KeyValueBatch;
pub(super) const SQL: &str = "CREATE TABLE _uqa_mvcc_native_occurrence_guards (table_name TEXT NOT NULL, document_id INTEGER NOT NULL CHECK(document_id >= -1), PRIMARY KEY(table_name, document_id)) WITHOUT ROWID";
impl NativeSnapshot {
pub(crate) fn occurrence_guard(
&self,
batch: &mut dyn KeyValueBatch,
table: &str,
owner: NativeRecordOwner,
document: i64,
) -> Result<()> {
self.put_row(
batch,
Family::OccurrenceGuards,
owner,
&[
ValueRef::Text(table.as_bytes()),
ValueRef::Integer(document),
],
)
}
pub(crate) fn reset_occurrence_rows(
&self,
batch: &mut dyn KeyValueBatch,
owner: NativeRecordOwner,
) -> Result<()> {
let key = NativeRecordIdentity::new(Family::OccurrenceGuards, owner)?
.encode_key(&[ValueRef::Integer(-1)], &self.control)?;
batch.fence_record(&key)?;
let key = NativeRecordIdentity::new(Family::OccurrenceFormats, owner)?
.encode_key(&[], &self.control)?;
batch.fence_record(&key)?;
Ok(())
}
}