use std::{fmt::Debug, future::Future};
use futures_core::Stream;
use crate::{AsyncRow, Id, Order, Query, Row, SubTableKey};
pub trait SubTable: Send + Sync {
type Error: Debug + Send + Sync;
type AsyncRow: AsyncRow;
type Stream: Stream<Item = Result<(Id, Self::AsyncRow), Self::Error>> + Send;
fn put(&self, data: &[Row]) -> impl Future<Output = Result<Vec<Id>, Self::Error>> + Send;
fn get(
&self,
id: Id,
) -> impl Future<Output = Result<Option<(Id, Self::AsyncRow)>, Self::Error>> + Send;
fn select(&self, q: &Query) -> impl Future<Output = Self::Stream> + Send;
fn scan(&self, begin_id: u64, order: Order) -> impl Future<Output = Self::Stream> + Send;
fn history(&self, id: Id, offset: usize) -> impl Future<Output = Self::Stream> + Send;
fn rm(&self, q: &Query) -> impl Future<Output = Result<u64, Self::Error>> + Send;
fn key(&self) -> &SubTableKey;
fn get_or_insert_with<F>(
&self,
query: &Query,
f: F,
) -> impl Future<Output = Result<(Id, Self::AsyncRow), Self::Error>> + Send
where
F: FnOnce() -> Row + Send;
}