use std::sync::Arc;
use uuid::Uuid;
use crate::meta_storage::mem::error::MemResult;
use crate::meta_storage::mem::store::MemStore;
use crate::meta_storage::mem::{MemMetaStorage, MemResolutionQueryBuilder, MemTicketQueryBuilder};
use crate::meta_storage::{MetaClientApi, MetaConnApi, MetaTxApi};
use crate::schema::{DimensionMetadata, RunFootprint, TableShape, TaskMetadata};
#[derive(Debug)]
pub struct MemConn {
store: Arc<MemStore>,
}
impl MemConn {
pub(super) fn new(store: Arc<MemStore>) -> Self {
Self { store }
}
}
impl MetaConnApi<MemMetaStorage> for MemConn {
async fn transaction(&mut self) -> MemResult<MemTx<'_>> {
Ok(MemTx { store: &self.store })
}
fn as_client(&self) -> MemClient<'_> {
MemClient(&self.store)
}
}
#[derive(Debug)]
pub struct MemTx<'a> {
store: &'a MemStore,
}
impl MetaTxApi<MemMetaStorage> for MemTx<'_> {
async fn commit(self) -> MemResult<()> {
Ok(())
}
async fn rollback(self) -> MemResult<()> {
Ok(())
}
fn as_client(&self) -> MemClient<'_> {
MemClient(self.store)
}
}
#[derive(Debug, Clone, Copy)]
pub struct MemClient<'a>(&'a MemStore);
impl MetaClientApi<MemMetaStorage> for MemClient<'_> {
fn ticket<const N: usize>(&self, task_meta: TaskMetadata<N>) -> MemTicketQueryBuilder<'_, N> {
self.0.ticket(task_meta)
}
fn resolution<const N: usize>(
&self,
dim_meta: DimensionMetadata<N>,
) -> MemResolutionQueryBuilder<'_, N> {
self.0.resolution(dim_meta)
}
async fn init_schema(&self) -> MemResult<()> {
Ok(())
}
async fn init_ticket_hash(&self) -> MemResult<()> {
Ok(())
}
async fn init_dimension_hash(&self) -> MemResult<()> {
Ok(())
}
async fn init_ticket_status_type(&self) -> MemResult<()> {
Ok(())
}
async fn init_ticket_summary(&self) -> MemResult<()> {
Ok(())
}
async fn init_footprint(&self) -> MemResult<TableShape> {
Ok(TableShape::CURRENT)
}
async fn clear_footprint(&self) -> MemResult<()> {
self.0.clear_footprint()
}
async fn get_footprint(&self) -> MemResult<Option<RunFootprint>> {
self.0.get_footprint()
}
async fn upsert_run(&self, footprint: &RunFootprint) -> MemResult<()> {
self.0.upsert_run(footprint)
}
async fn put_execution(&self, run_id: Uuid, execution_id: Uuid) -> MemResult<()> {
self.0.put_execution(run_id, execution_id)
}
async fn update_execution_on_finish(
&self,
footprint: &RunFootprint,
execution_id: Uuid,
) -> MemResult<()> {
self.0.update_execution_on_finish(footprint, execution_id)
}
}