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 match self {
31 ScalarImpl::Int16(v) => v.to_sql(ty, out),
32 ScalarImpl::Int32(v) => v.to_sql(ty, out),
33 ScalarImpl::Int64(v) => v.to_sql(ty, out),
34 ScalarImpl::Serial(v) => v.to_sql(ty, out),
35 ScalarImpl::Float32(v) => v.to_sql(ty, out),
36 ScalarImpl::Float64(v) => v.to_sql(ty, out),
37 ScalarImpl::Utf8(v) => v.to_sql(ty, out),
38 ScalarImpl::Bool(v) => v.to_sql(ty, out),
39 ScalarImpl::Decimal(v) => v.to_sql(ty, out),
40 ScalarImpl::Interval(v) => v.to_sql(ty, out),
41 ScalarImpl::Date(v) => v.to_sql(ty, out),
42 ScalarImpl::Timestamp(v) => v.to_sql(ty, out),
43 ScalarImpl::Timestamptz(v) => v.to_sql(ty, out),
44 ScalarImpl::Time(v) => v.to_sql(ty, out),
45 ScalarImpl::Bytea(v) => (&**v).to_sql(ty, out),
46 ScalarImpl::Jsonb(v) => v.to_sql(ty, out),
47 ScalarImpl::Vector(_) => todo!("VECTOR_PLACEHOLDER"),
48 ScalarImpl::Int256(_) | ScalarImpl::Struct(_) | ScalarImpl::List(_) => {
49 bail_not_implemented!("the postgres encoding for {ty} is unsupported")
50 }
51 ScalarImpl::Map(_) => todo!(),
52 }
53 }
54
55 fn accepts(_ty: &Type) -> bool
57 where
58 Self: Sized,
59 {
60 true
61 }
62}
63
64impl ToSql for ScalarRefImpl<'_> {
65 to_sql_checked!();
66
67 fn to_sql(&self, ty: &Type, out: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>>
68 where
69 Self: Sized,
70 {
71 match self {
72 ScalarRefImpl::Int16(v) => v.to_sql(ty, out),
73 ScalarRefImpl::Int32(v) => v.to_sql(ty, out),
74 ScalarRefImpl::Int64(v) => v.to_sql(ty, out),
75 ScalarRefImpl::Serial(v) => v.to_sql(ty, out),
76 ScalarRefImpl::Float32(v) => v.to_sql(ty, out),
77 ScalarRefImpl::Float64(v) => v.to_sql(ty, out),
78 ScalarRefImpl::Utf8(v) => v.to_sql(ty, out),
79 ScalarRefImpl::Bool(v) => v.to_sql(ty, out),
80 ScalarRefImpl::Decimal(v) => v.to_sql(ty, out),
81 ScalarRefImpl::Interval(v) => v.to_sql(ty, out),
82 ScalarRefImpl::Date(v) => v.to_sql(ty, out),
83 ScalarRefImpl::Timestamp(v) => v.to_sql(ty, out),
84 ScalarRefImpl::Timestamptz(v) => v.to_sql(ty, out),
85 ScalarRefImpl::Time(v) => v.to_sql(ty, out),
86 ScalarRefImpl::Bytea(v) => (&**v).to_sql(ty, out),
87 ScalarRefImpl::Jsonb(v) => v.to_sql(ty, out),
88 ScalarRefImpl::Vector(_) => todo!("VECTOR_PLACEHOLDER"),
89 ScalarRefImpl::Int256(_) | ScalarRefImpl::Struct(_) | ScalarRefImpl::List(_) => {
90 bail_not_implemented!("the postgres encoding for {ty} is unsupported")
91 }
92 ScalarRefImpl::Map(_) => todo!(),
93 }
94 }
95
96 fn accepts(_ty: &Type) -> bool
98 where
99 Self: Sized,
100 {
101 true
102 }
103}