use std::sync::Arc;
use vortex_session::Ref;
use vortex_session::SessionExt;
use vortex_session::registry::Registry;
use crate::dtype::extension::ExtDTypePluginRef;
use crate::dtype::extension::ExtVTable;
use crate::extension::datetime::Date;
use crate::extension::datetime::Time;
use crate::extension::datetime::Timestamp;
pub type ExtDTypeRegistry = Registry<ExtDTypePluginRef>;
#[derive(Debug)]
pub struct DTypeSession {
registry: ExtDTypeRegistry,
}
impl Default for DTypeSession {
fn default() -> Self {
let this = Self {
registry: Registry::default(),
};
this.register(Date);
this.register(Time);
this.register(Timestamp);
this
}
}
impl DTypeSession {
pub fn register<V: ExtVTable>(&self, vtable: V) {
self.registry
.register(vtable.id(), Arc::new(vtable) as ExtDTypePluginRef);
}
pub fn registry(&self) -> &ExtDTypeRegistry {
&self.registry
}
}
pub trait DTypeSessionExt: SessionExt {
fn dtypes(&self) -> Ref<'_, DTypeSession>;
}
impl<S: SessionExt> DTypeSessionExt for S {
fn dtypes(&self) -> Ref<'_, DTypeSession> {
self.get::<DTypeSession>()
}
}