Skip to content

Commit 5c6f839

Browse files
committed
Added support for INET type in PostgreSQL, IPv4Address/IPv6Address in Python
1 parent 0b2cdca commit 5c6f839

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/value_converter.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ impl PythonDTO {
7171
PythonDTO::PyIntI64(_) => Ok(tokio_postgres::types::Type::INT8_ARRAY),
7272
PythonDTO::PyFloat32(_) => Ok(tokio_postgres::types::Type::FLOAT4_ARRAY),
7373
PythonDTO::PyFloat64(_) => Ok(tokio_postgres::types::Type::FLOAT8_ARRAY),
74+
PythonDTO::PyIpAddress(_) => Ok(tokio_postgres::types::Type::INET_ARRAY),
7475
PythonDTO::PyJson(_) => Ok(tokio_postgres::types::Type::JSONB_ARRAY),
7576
_ => Err(RustPSQLDriverError::PyToRustValueConversionError(
7677
"Can't process array type, your type doesn't have support yet".into(),
@@ -416,6 +417,8 @@ pub fn postgres_to_py(
416417
None => Ok(py.None()),
417418
}
418419
}
420+
// ---------- IpAddress Types ----------
421+
Type::INET => Ok(row.try_get::<_, Option<IpAddr>>(column_i)?.to_object(py)),
419422
// ---------- Array Text Types ----------
420423
// Convert ARRAY of TEXT or VARCHAR into Vec<String>, then into list[str]
421424
Type::TEXT_ARRAY | Type::VARCHAR_ARRAY => Ok(row
@@ -462,6 +465,10 @@ pub fn postgres_to_py(
462465
}
463466
None => Ok(py.None().to_object(py)),
464467
},
468+
// Convert ARRAY of INET into Vec<INET>, then into list[IPv4Address | IPv6Address]
469+
Type::INET_ARRAY => Ok(row
470+
.try_get::<_, Option<Vec<IpAddr>>>(column_i)?
471+
.to_object(py)),
465472
Type::JSONB | Type::JSON => {
466473
let db_json = row.try_get::<_, Option<Value>>(column_i)?;
467474

0 commit comments

Comments
 (0)