sqlx_exasol/types/
uuid.rs1use serde::Deserialize;
2use sqlx_core::{
3 decode::Decode,
4 encode::{Encode, IsNull},
5 error::BoxDynError,
6 types::Type,
7};
8use uuid::Uuid;
9
10use crate::{
11 arguments::ExaBuffer,
12 database::Exasol,
13 type_info::{ExaDataType, ExaTypeInfo, HashType},
14 value::ExaValueRef,
15};
16
17impl Type<Exasol> for Uuid {
18 fn type_info() -> ExaTypeInfo {
19 ExaDataType::HashType(HashType {}).into()
20 }
21
22 fn compatible(ty: &ExaTypeInfo) -> bool {
23 <Self as Type<Exasol>>::type_info().compatible(ty)
24 }
25}
26
27impl Encode<'_, Exasol> for Uuid {
28 fn encode_by_ref(&self, buf: &mut ExaBuffer) -> Result<IsNull, BoxDynError> {
29 buf.append(self.simple())?;
30 Ok(IsNull::No)
31 }
32
33 fn produces(&self) -> Option<ExaTypeInfo> {
34 Some(ExaDataType::HashType(HashType {}).into())
35 }
36
37 fn size_hint(&self) -> usize {
38 32
40 }
41}
42
43impl Decode<'_, Exasol> for Uuid {
44 fn decode(value: ExaValueRef<'_>) -> Result<Self, BoxDynError> {
45 <Self as Deserialize>::deserialize(value.value).map_err(From::from)
46 }
47}