risingwave_common/types/
to_sql.rs1use std::error::Error;
16
17use bytes::BytesMut;
18use postgres_types::{IsNull, ToSql, Type, to_sql_checked};
19use risingwave_common::types::ScalarRefImpl;
20
21use crate::types::ScalarImpl;
22
23impl ToSql for ScalarImpl {
24 to_sql_checked!();
25
26 fn to_sql(&self, ty: &Type, out: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>>
27 where
28 Self: Sized,
29 {
30 self.as_scalar_ref_impl().to_sql(ty, out)
31 }
32
33 fn accepts(_ty: &Type) -> bool
35 where
36 Self: Sized,
37 {
38 true
39 }
40}
41
42impl ToSql for ScalarRefImpl<'_> {
43 to_sql_checked!();
44
45 fn to_sql(&self, ty: &Type, out: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>>
46 where
47 Self: Sized,
48 {
49 match self {
50 ScalarRefImpl::Int16(v) => v.to_sql(ty, out),
51 ScalarRefImpl::Int32(v) => v.to_sql(ty, out),
52 ScalarRefImpl::Int64(v) => v.to_sql(ty, out),
53 ScalarRefImpl::Serial(v) => v.to_sql(ty, out),
54 ScalarRefImpl::Float32(v) => v.to_sql(ty, out),
55 ScalarRefImpl::Float64(v) => v.to_sql(ty, out),
56 ScalarRefImpl::Utf8(v) => v.to_sql(ty, out),
57 ScalarRefImpl::Bool(v) => v.to_sql(ty, out),
58 ScalarRefImpl::Decimal(v) => v.to_sql(ty, out),
59 ScalarRefImpl::Interval(v) => v.to_sql(ty, out),
60 ScalarRefImpl::Date(v) => v.to_sql(ty, out),
61 ScalarRefImpl::Timestamp(v) => v.to_sql(ty, out),
62 ScalarRefImpl::Timestamptz(v) => v.to_sql(ty, out),
63 ScalarRefImpl::Time(v) => v.to_sql(ty, out),
64 ScalarRefImpl::Bytea(v) => (&**v).to_sql(ty, out),
65 ScalarRefImpl::Jsonb(v) => v.to_sql(ty, out),
66 ScalarRefImpl::Vector(_)
67 | ScalarRefImpl::Int256(_)
68 | ScalarRefImpl::Struct(_)
69 | ScalarRefImpl::List(_) => {
70 bail_not_implemented!("the postgres encoding for {ty} is unsupported")
71 }
72 ScalarRefImpl::Map(_) => todo!(),
73 }
74 }
75
76 fn accepts(_ty: &Type) -> bool
78 where
79 Self: Sized,
80 {
81 true
82 }
83}