clickhouse_client/value/ext/
uuid.rs1pub use uuid::Uuid;
4
5use crate::{
6 error::Error,
7 value::{ChValue, Type, Value},
8};
9
10impl ChValue for Uuid {
11 fn ch_type() -> Type {
12 Type::UUID
13 }
14
15 fn into_ch_value(self) -> Value {
16 Value::UUID(self.into_bytes())
17 }
18
19 fn from_ch_value(value: Value) -> Result<Self, Error> {
20 match value {
21 Value::UUID(v) => Ok(Uuid::from_bytes(v)),
22 _ => Err(Error::new("Cannot convert Value to base type")),
23 }
24 }
25}
26
27impl ChValue for Option<Uuid> {
28 fn ch_type() -> Type {
29 Type::NullableUUID
30 }
31
32 fn into_ch_value(self) -> Value {
33 match self {
34 Some(v) => Value::UUID(v.into_bytes()),
35 None => Value::UUID([0; 16]),
36 }
37 }
38
39 fn from_ch_value(value: Value) -> Result<Self, Error> {
40 match value {
41 Value::NullableUUID(v) => Ok(v.map(Uuid::from_bytes)),
42 _ => Err(Error::new("Cannot convert Value to base type")),
43 }
44 }
45}