1use crate::OracleTypeInfo;
2use crate::types::value::MISSING_STRING_VALUE;
3use rbdc::Error;
4use std::borrow::Cow;
5use std::sync::Arc;
6
7#[derive(Clone, Copy)]
8pub struct OracleValueRef<'r>(&'r OracleValue);
9
10impl<'r> OracleValueRef<'r> {
11 pub(crate) fn value(value: &'r OracleValue) -> Self {
12 Self(value)
13 }
14
15 pub fn to_owned(&self) -> OracleValue {
16 self.0.clone()
17 }
18
19 pub fn type_info(&self) -> Cow<'_, OracleTypeInfo> {
20 Cow::Borrowed(&self.0.type_info)
21 }
22
23 pub fn is_null(&self) -> bool {
24 self.0.is_null
25 }
26
27 pub fn text(&self) -> Result<&'r str, Error> {
28 self.0
29 .text
30 .as_deref()
31 .ok_or_else(|| Error::from(MISSING_STRING_VALUE))
32 }
33
34 pub fn blob(&self) -> Option<&'r [u8]> {
35 self.0.binary.as_deref()
36 }
37}
38
39#[derive(Debug, Clone)]
40pub struct OracleValue {
41 pub(crate) text: Option<Arc<str>>,
42 pub(crate) binary: Option<Arc<[u8]>>,
43 pub(crate) type_info: OracleTypeInfo,
44 pub(crate) is_null: bool,
45}
46
47impl OracleValue {
48 pub fn new(
49 text: Option<String>,
50 binary: Option<Vec<u8>>,
51 type_info: OracleTypeInfo,
52 is_null: bool,
53 ) -> Self {
54 Self {
55 text: text.map(Into::into),
56 binary: binary.map(Into::into),
57 type_info,
58 is_null,
59 }
60 }
61
62 pub fn as_ref(&self) -> OracleValueRef<'_> {
63 OracleValueRef::value(self)
64 }
65}