use std::borrow::Cow;
use crate::{types::Type, KlickhouseError, Result, Value};
mod raw_row;
mod std_deserialize;
mod std_serialize;
pub use raw_row::*;
mod unit_value;
pub use unit_value::*;
mod vec_tuple;
pub use vec_tuple::*;
#[cfg(feature = "serde")]
mod json;
#[cfg(feature = "serde")]
pub use json::*;
pub trait ToSql {
fn to_sql(self, type_hint: Option<&Type>) -> Result<Value>;
}
impl ToSql for Value {
fn to_sql(self, _type_hint_: Option<&Type>) -> Result<Value> {
Ok(self)
}
}
pub fn unexpected_type(type_: &Type) -> KlickhouseError {
KlickhouseError::DeserializeError(format!("unexpected type: {}", type_))
}
pub trait FromSql: Sized {
fn from_sql(type_: &Type, value: Value) -> Result<Self>;
}
impl FromSql for Value {
fn from_sql(_type_: &Type, value: Value) -> Result<Self> {
Ok(value)
}
}
pub trait Row: Sized {
const COLUMN_COUNT: Option<usize>;
fn column_names() -> Option<Vec<Cow<'static, str>>>;
fn deserialize_row(map: Vec<(&str, &Type, Value)>) -> Result<Self>;
fn serialize_row(
self,
type_hints: &indexmap::IndexMap<String, Type>,
) -> Result<Vec<(Cow<'static, str>, Value)>>;
}