clickhouse_arrow/native/
convert.rs1use std::borrow::Cow;
2
3use crate::{Error, Result, Type, Value};
4
5pub mod raw_row;
6pub mod std_deserialize;
7pub mod std_serialize;
8pub use raw_row::*;
9pub mod unit_value;
10
11pub type ColumnDefinition<T = Value> = (String, Type, Option<T>);
13
14pub trait ToSql {
16 fn to_sql(self, type_hint: Option<&Type>) -> Result<Value>;
18}
19
20impl ToSql for Value {
21 fn to_sql(self, _type_hint_: Option<&Type>) -> Result<Value> { Ok(self) }
22}
23
24pub fn unexpected_type(type_: &Type) -> Error {
25 Error::DeserializeError(format!("unexpected type: {type_}"))
26}
27
28pub trait FromSql: Sized {
30 fn from_sql(type_: &Type, value: Value) -> Result<Self>;
32}
33
34impl FromSql for Value {
35 fn from_sql(_type_: &Type, value: Value) -> Result<Self> { Ok(value) }
36}
37
38pub trait Row: Sized {
53 const COLUMN_COUNT: Option<usize>;
55
56 fn column_names() -> Option<Vec<Cow<'static, str>>>;
58
59 fn to_schema() -> Option<Vec<ColumnDefinition<Value>>>;
61
62 fn deserialize_row(map: Vec<(&str, &Type, Value)>) -> Result<Self>;
64
65 fn serialize_row(
67 self,
68 type_hints: &[(String, Type)],
69 ) -> Result<Vec<(Cow<'static, str>, Value)>>;
70}