Skip to content

Commit 50bde9d

Browse files
committed
Range and array types
Signed-off-by: itowlson <[email protected]>
1 parent 292e705 commit 50bde9d

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

crates/factor-outbound-pg/src/client.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ fn to_sql_parameter(value: &ParameterValue) -> Result<Box<dyn ToSql + Send + Syn
192192
let r = postgres_range::Range::new(lbound, ubound);
193193
Ok(Box::new(r))
194194
}
195+
ParameterValue::ArrayInt32(vs) => Ok(Box::new(vs.to_owned())),
196+
ParameterValue::ArrayInt64(vs) => Ok(Box::new(vs.to_owned())),
197+
ParameterValue::ArrayStr(vs) => Ok(Box::new(vs.to_owned())),
195198
ParameterValue::DbNull => Ok(Box::new(PgNull)),
196199
}
197200
}
@@ -236,6 +239,9 @@ fn convert_data_type(pg_type: &Type) -> DbDataType {
236239
Type::NUMERIC => DbDataType::Decimal,
237240
Type::INT4_RANGE => DbDataType::Range32,
238241
Type::INT8_RANGE => DbDataType::Range64,
242+
Type::INT4_ARRAY => DbDataType::ArrayInt32,
243+
Type::INT8_ARRAY => DbDataType::ArrayInt64,
244+
Type::TEXT_ARRAY | Type::VARCHAR_ARRAY | Type::BPCHAR_ARRAY => DbDataType::ArrayStr,
239245
_ => {
240246
tracing::debug!("Couldn't convert Postgres type {} to WIT", pg_type.name(),);
241247
DbDataType::Other
@@ -359,7 +365,7 @@ fn convert_entry(row: &Row, index: usize) -> anyhow::Result<DbValue> {
359365
match value {
360366
Some(v) => {
361367
let lower = v.lower().map(tuplify_range_bound);
362-
let upper = v.lower().map(tuplify_range_bound);
368+
let upper = v.upper().map(tuplify_range_bound);
363369
DbValue::Range32((lower, upper))
364370
}
365371
None => DbValue::DbNull,
@@ -370,12 +376,33 @@ fn convert_entry(row: &Row, index: usize) -> anyhow::Result<DbValue> {
370376
match value {
371377
Some(v) => {
372378
let lower = v.lower().map(tuplify_range_bound);
373-
let upper = v.lower().map(tuplify_range_bound);
379+
let upper = v.upper().map(tuplify_range_bound);
374380
DbValue::Range64((lower, upper))
375381
}
376382
None => DbValue::DbNull,
377383
}
378384
}
385+
&Type::INT4_ARRAY => {
386+
let value: Option<Vec<Option<i32>>> = row.try_get(index)?;
387+
match value {
388+
Some(v) => DbValue::ArrayInt32(v),
389+
None => DbValue::DbNull,
390+
}
391+
}
392+
&Type::INT8_ARRAY => {
393+
let value: Option<Vec<Option<i64>>> = row.try_get(index)?;
394+
match value {
395+
Some(v) => DbValue::ArrayInt64(v),
396+
None => DbValue::DbNull,
397+
}
398+
}
399+
&Type::TEXT_ARRAY | &Type::VARCHAR_ARRAY | &Type::BPCHAR_ARRAY => {
400+
let value: Option<Vec<Option<String>>> = row.try_get(index)?;
401+
match value {
402+
Some(v) => DbValue::ArrayStr(v),
403+
None => DbValue::DbNull,
404+
}
405+
}
379406
t => {
380407
tracing::debug!(
381408
"Couldn't convert Postgres type {} in column {}",

crates/world/src/conversions.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ mod rdbms_types {
122122
pg4::DbValue::Decimal(_) => pg3::DbValue::Unsupported,
123123
pg4::DbValue::Range32(_) => pg3::DbValue::Unsupported,
124124
pg4::DbValue::Range64(_) => pg3::DbValue::Unsupported,
125+
pg4::DbValue::ArrayInt32(_) => pg3::DbValue::Unsupported,
126+
pg4::DbValue::ArrayInt64(_) => pg3::DbValue::Unsupported,
127+
pg4::DbValue::ArrayStr(_) => pg3::DbValue::Unsupported,
125128
pg4::DbValue::DbNull => pg3::DbValue::DbNull,
126129
pg4::DbValue::Unsupported => pg3::DbValue::Unsupported,
127130
}
@@ -185,6 +188,9 @@ mod rdbms_types {
185188
pg4::DbDataType::Decimal => pg3::DbDataType::Other,
186189
pg4::DbDataType::Range32 => pg3::DbDataType::Other,
187190
pg4::DbDataType::Range64 => pg3::DbDataType::Other,
191+
pg4::DbDataType::ArrayInt32 => pg3::DbDataType::Other,
192+
pg4::DbDataType::ArrayInt64 => pg3::DbDataType::Other,
193+
pg4::DbDataType::ArrayStr => pg3::DbDataType::Other,
188194
pg4::DbDataType::Other => pg3::DbDataType::Other,
189195
}
190196
}

wit/deps/[email protected]/postgres.wit

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ interface postgres {
3030
decimal,
3131
range32,
3232
range64,
33+
array-int32,
34+
array-int64,
35+
array-str,
3336
other,
3437
}
3538

@@ -56,6 +59,9 @@ interface postgres {
5659
decimal(string), // I admit defeat. Base 10
5760
range32(tuple<option<tuple<s32, range-bound-kind>>, option<tuple<s32, range-bound-kind>>>),
5861
range64(tuple<option<tuple<s64, range-bound-kind>>, option<tuple<s64, range-bound-kind>>>),
62+
array-int32(list<option<s32>>),
63+
array-int64(list<option<s64>>),
64+
array-str(list<option<string>>),
5965
db-null,
6066
unsupported,
6167
}
@@ -83,6 +89,9 @@ interface postgres {
8389
decimal(string), // base 10
8490
range32(tuple<option<tuple<s32, range-bound-kind>>, option<tuple<s32, range-bound-kind>>>),
8591
range64(tuple<option<tuple<s64, range-bound-kind>>, option<tuple<s64, range-bound-kind>>>),
92+
array-int32(list<option<s32>>),
93+
array-int64(list<option<s64>>),
94+
array-str(list<option<string>>),
8695
db-null,
8796
}
8897

0 commit comments

Comments
 (0)