sqlx_exasol/
value.rs

1use std::borrow::Cow;
2
3use serde_json::Value as JsonValue;
4use sqlx_core::{
5    database::Database,
6    value::{Value, ValueRef},
7};
8
9use crate::{database::Exasol, type_info::ExaTypeInfo};
10
11/// Implementor of [`Value`].
12#[derive(Clone, Debug)]
13pub struct ExaValue {
14    pub(crate) value: JsonValue,
15    type_info: ExaTypeInfo,
16}
17
18/// Implementor of [`ValueRef`].
19#[derive(Clone, Debug)]
20pub struct ExaValueRef<'r> {
21    pub(crate) value: &'r JsonValue,
22    pub(crate) type_info: &'r ExaTypeInfo,
23}
24
25impl Value for ExaValue {
26    type Database = Exasol;
27
28    fn as_ref(&self) -> <Self::Database as Database>::ValueRef<'_> {
29        ExaValueRef {
30            value: &self.value,
31            type_info: &self.type_info,
32        }
33    }
34
35    fn type_info(&self) -> Cow<'_, <Self::Database as Database>::TypeInfo> {
36        Cow::Borrowed(&self.type_info)
37    }
38
39    fn is_null(&self) -> bool {
40        self.value.is_null()
41    }
42}
43
44impl<'r> ValueRef<'r> for ExaValueRef<'r> {
45    type Database = Exasol;
46
47    fn to_owned(&self) -> <Self::Database as Database>::Value {
48        ExaValue {
49            value: self.value.clone(),
50            type_info: *self.type_info,
51        }
52    }
53
54    fn type_info(&self) -> Cow<'_, <Self::Database as Database>::TypeInfo> {
55        Cow::Borrowed(self.type_info)
56    }
57
58    fn is_null(&self) -> bool {
59        self.value.is_null()
60    }
61}