Skip to content

Commit dec9bd5

Browse files
committed
feat: Add support for postgres 'point' type
1 parent 25e4e87 commit dec9bd5

File tree

11 files changed

+85
-2
lines changed

11 files changed

+85
-2
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ time = { version = "0.3.36", default-features = false, optional = true, features
4141
ipnetwork = { version = "0.20", default-features = false, optional = true }
4242
mac_address = { version = "1.1", default-features = false, optional = true }
4343
ordered-float = { version = "4.6", default-features = false, optional = true }
44+
sqlx = { version = "0.8", default-features = false, optional = true }
4445

4546
[dev-dependencies]
4647
sea-query = { path = ".", features = ["tests-cfg"] }
@@ -68,6 +69,7 @@ with-uuid = ["uuid"]
6869
with-time = ["time"]
6970
with-ipnetwork = ["ipnetwork"]
7071
with-mac_address = ["mac_address"]
72+
with-postgres-point = ["sqlx", "sqlx/postgres"]
7173
tests-cfg = []
7274
all-features = [
7375
"backend-mysql",

sea-query-binder/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
[package]
55
name = "sea-query-binder"
6-
version = "0.7.0"
6+
version = "0.8.0-rc.2"
77
authors = [ "Valentin Tolmer <[email protected]>", "Ivan Krivosheev <[email protected]>" ]
8-
edition = "2021"
8+
edition = "2024"
99
description = "Driver library for using SeaQuery with SQLx"
1010
license = "MIT OR Apache-2.0"
1111
documentation = "https://docs.rs/sea-query"
@@ -42,6 +42,7 @@ with-uuid = ["sqlx?/uuid", "sea-query/with-uuid", "uuid"]
4242
with-time = ["sqlx?/time", "sea-query/with-time", "time"]
4343
with-ipnetwork = ["sqlx?/ipnetwork", "sea-query/with-ipnetwork", "ipnetwork"]
4444
with-mac_address = ["sqlx?/mac_address", "sea-query/with-mac_address", "mac_address"]
45+
with-postgres-point = ["sea-query/with-postgres-point"]
4546
postgres-array = ["sea-query/postgres-array"]
4647
postgres-vector = ["sea-query/postgres-vector", "pgvector/sqlx"]
4748
runtime-async-std = ["sqlx?/runtime-async-std"]

sea-query-binder/src/sqlx_postgres.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ impl sqlx::IntoArguments<'_, sqlx::postgres::Postgres> for SqlxValues {
129129
Value::MacAddress(mac) => {
130130
let _ = args.add(mac.as_deref());
131131
}
132+
#[cfg(feature = "with-postgres-point")]
133+
Value::Point(point) => {
134+
let _ = args.add(point.as_deref());
135+
}
132136
#[cfg(feature = "postgres-array")]
133137
Value::Array(ty, v) => match ty {
134138
ArrayType::Bool => {

sea-query-postgres/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ postgres-array = ["postgres-types/array-impls", "sea-query/postgres-array"]
3939
postgres-vector = ["sea-query/postgres-vector", "pgvector/postgres"]
4040
with-ipnetwork = ["postgres-types/with-cidr-0_2", "sea-query/with-ipnetwork", "ipnetwork", "cidr"]
4141
with-mac_address = ["postgres-types/with-eui48-1", "sea-query/with-mac_address", "mac_address", "eui48"]
42+
with-postgres-point = ["sea-query/with-postgres-point"]

sea-query-postgres/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ impl ToSql for PostgresValue {
137137
.map(|v| MacAddress::new(v.bytes()))
138138
.to_sql(ty, out)
139139
}
140+
#[cfg(feature = "with-postgres-point")]
141+
Value::Point(v) => v.as_deref().to_sql(ty, out),
140142
}
141143
}
142144

src/backend/mysql/table.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ impl TableBuilder for MysqlQueryBuilder {
9595
ColumnType::Inet => unimplemented!("Inet is not available in MySQL."),
9696
ColumnType::MacAddr => unimplemented!("MacAddr is not available in MySQL."),
9797
ColumnType::LTree => unimplemented!("LTree is not available in MySQL."),
98+
ColumnType::Point => unimplemented!("Point is not available in MySQL."),
9899
}
99100
)
100101
.unwrap();

src/backend/postgres/table.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ impl TableBuilder for PostgresQueryBuilder {
8282
ColumnType::MacAddr => "macaddr".into(),
8383
ColumnType::Year => unimplemented!("Year is not available in Postgres."),
8484
ColumnType::LTree => "ltree".into(),
85+
ColumnType::Point => "point".into(),
8586
}
8687
)
8788
.unwrap()

src/backend/query_builder.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,8 @@ pub trait QueryBuilder:
11091109
Value::Array(_, None) => write!(s, "NULL").unwrap(),
11101110
#[cfg(feature = "postgres-vector")]
11111111
Value::Vector(None) => write!(s, "NULL").unwrap(),
1112+
#[cfg(feature = "with-postgres-point")]
1113+
Value::Point(None) => write!(s, "NULL").unwrap(),
11121114
Value::Bool(Some(b)) => write!(s, "{}", if *b { "TRUE" } else { "FALSE" }).unwrap(),
11131115
Value::TinyInt(Some(v)) => write!(s, "{v}").unwrap(),
11141116
Value::SmallInt(Some(v)) => write!(s, "{v}").unwrap(),
@@ -1203,6 +1205,8 @@ pub trait QueryBuilder:
12031205
Value::IpNetwork(Some(v)) => write!(s, "'{v}'").unwrap(),
12041206
#[cfg(feature = "with-mac_address")]
12051207
Value::MacAddress(Some(v)) => write!(s, "'{v}'").unwrap(),
1208+
#[cfg(feature = "with-postgres-point")]
1209+
Value::Point(Some(v)) => write!(s, "'({},{})'", v.x, v.y).unwrap(),
12061210
};
12071211
s
12081212
}

src/backend/sqlite/table.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ impl SqliteQueryBuilder {
192192
ColumnType::Bit(_) => unimplemented!("Bit is not available in Sqlite."),
193193
ColumnType::VarBit(_) => unimplemented!("VarBit is not available in Sqlite."),
194194
ColumnType::LTree => unimplemented!("LTree is not available in Sqlite."),
195+
ColumnType::Point => unimplemented!("Point is not available in MySQL."),
195196
}
196197
)
197198
.unwrap()

src/table/column.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub trait IntoColumnDef {
5757
/// | Inet | N/A | inet | N/A |
5858
/// | MacAddr | N/A | macaddr | N/A |
5959
/// | LTree | N/A | ltree | N/A |
60+
/// | Point | N/A | point | N/A |
6061
#[non_exhaustive]
6162
#[derive(Debug, Clone)]
6263
pub enum ColumnType {
@@ -102,6 +103,7 @@ pub enum ColumnType {
102103
Inet,
103104
MacAddr,
104105
LTree,
106+
Point,
105107
}
106108

107109
/// Length for var-char/binary; default to 255

0 commit comments

Comments
 (0)