use std::borrow::Cow;
use crate::{Error, Result, Type, Value};
pub mod raw_row;
pub mod std_deserialize;
pub mod std_serialize;
pub use raw_row::*;
pub mod unit_value;
pub type ColumnDefinition<T = Value> = (String, Type, Option<T>);
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) -> Error {
Error::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 to_schema() -> Option<Vec<ColumnDefinition<Value>>>;
fn deserialize_row(map: Vec<(&str, &Type, Value)>) -> Result<Self>;
fn serialize_row(
self,
type_hints: &[(String, Type)],
) -> Result<Vec<(Cow<'static, str>, Value)>>;
}