use crate::db_type::{
check_key_type, check_key_type_from_key_definition, KeyOptions, Result, ToInput, ToKey,
ToKeyDefinition,
};
use crate::watch;
use crate::watch::query::internal;
use crate::watch::MpscReceiver;
pub struct WatchGet<'db, 'w> {
pub(crate) internal: &'w internal::InternalWatch<'db>,
}
impl WatchGet<'_, '_> {
pub fn primary<T: ToInput>(
&self,
key: impl ToKey,
) -> Result<(MpscReceiver<watch::Event>, u64)> {
let model = T::native_db_model();
check_key_type(&model, &key)?;
self.internal.watch_primary::<T>(key)
}
pub fn secondary<T: ToInput>(
&self,
key_def: impl ToKeyDefinition<KeyOptions>,
key: impl ToKey,
) -> Result<(MpscReceiver<watch::Event>, u64)> {
check_key_type_from_key_definition(&key_def.key_definition(), &key)?;
self.internal.watch_secondary::<T>(&key_def, key)
}
}