Skip to content

Commit a9074c0

Browse files
committed
Range and array types
Signed-off-by: itowlson <[email protected]>
1 parent fe56868 commit a9074c0

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
@@ -231,6 +231,9 @@ fn to_sql_parameter(value: &ParameterValue) -> Result<Box<dyn ToSql + Send + Syn
231231
let r = postgres_range::Range::new(lbound, ubound);
232232
Ok(Box::new(r))
233233
}
234+
ParameterValue::ArrayInt32(vs) => Ok(Box::new(vs.to_owned())),
235+
ParameterValue::ArrayInt64(vs) => Ok(Box::new(vs.to_owned())),
236+
ParameterValue::ArrayStr(vs) => Ok(Box::new(vs.to_owned())),
234237
ParameterValue::DbNull => Ok(Box::new(PgNull)),
235238
}
236239
}
@@ -275,6 +278,9 @@ fn convert_data_type(pg_type: &Type) -> DbDataType {
275278
Type::NUMERIC => DbDataType::Decimal,
276279
Type::INT4_RANGE => DbDataType::Range32,
277280
Type::INT8_RANGE => DbDataType::Range64,
281+
Type::INT4_ARRAY => DbDataType::ArrayInt32,
282+
Type::INT8_ARRAY => DbDataType::ArrayInt64,
283+
Type::TEXT_ARRAY | Type::VARCHAR_ARRAY | Type::BPCHAR_ARRAY => DbDataType::ArrayStr,
278284
_ => {
279285
tracing::debug!("Couldn't convert Postgres type {} to WIT", pg_type.name(),);
280286
DbDataType::Other
@@ -398,7 +404,7 @@ fn convert_entry(row: &Row, index: usize) -> anyhow::Result<DbValue> {
398404
match value {
399405
Some(v) => {
400406
let lower = v.lower().map(tuplify_range_bound);
401-
let upper = v.lower().map(tuplify_range_bound);
407+
let upper = v.upper().map(tuplify_range_bound);
402408
DbValue::Range32((lower, upper))
403409
}
404410
None => DbValue::DbNull,
@@ -409,12 +415,33 @@ fn convert_entry(row: &Row, index: usize) -> anyhow::Result<DbValue> {
409415
match value {
410416
Some(v) => {
411417
let lower = v.lower().map(tuplify_range_bound);
412-
let upper = v.lower().map(tuplify_range_bound);
418+
let upper = v.upper().map(tuplify_range_bound);
413419
DbValue::Range64((lower, upper))
414420
}
415421
None => DbValue::DbNull,
416422
}
417423
}
424+
&Type::INT4_ARRAY => {
425+
let value: Option<Vec<Option<i32>>> = row.try_get(index)?;
426+
match value {
427+
Some(v) => DbValue::ArrayInt32(v),
428+
None => DbValue::DbNull,
429+
}
430+
}
431+
&Type::INT8_ARRAY => {
432+
let value: Option<Vec<Option<i64>>> = row.try_get(index)?;
433+
match value {
434+
Some(v) => DbValue::ArrayInt64(v),
435+
None => DbValue::DbNull,
436+
}
437+
}
438+
&Type::TEXT_ARRAY | &Type::VARCHAR_ARRAY | &Type::BPCHAR_ARRAY => {
439+
let value: Option<Vec<Option<String>>> = row.try_get(index)?;
440+
match value {
441+
Some(v) => DbValue::ArrayStr(v),
442+
None => DbValue::DbNull,
443+
}
444+
}
418445
t => {
419446
tracing::debug!(
420447
"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)