Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ time = { version = "0.3.36", default-features = false, optional = true, features
ipnetwork = { version = "0.20", default-features = false, optional = true }
mac_address = { version = "1.1", default-features = false, optional = true }
ordered-float = { version = "4.6", default-features = false, optional = true }
geo-types = { version = "0.7", default-features = false, optional = true }

[dev-dependencies]
sea-query = { path = ".", features = ["tests-cfg"] }
Expand Down Expand Up @@ -68,6 +69,7 @@ with-uuid = ["uuid"]
with-time = ["time"]
with-ipnetwork = ["ipnetwork"]
with-mac_address = ["mac_address"]
with-postgres-point = ["dep:geo-types", "dep:postgres-types", "postgres-types/with-geo-types-0_7"]
tests-cfg = []
all-features = [
"backend-mysql",
Expand All @@ -91,6 +93,7 @@ all-types = [
"with-time",
"with-ipnetwork",
"with-mac_address",
"with-postgres-point",
]
option-more-parentheses = []
option-sqlite-exact-column-type = []
Expand Down
1 change: 1 addition & 0 deletions sea-query-binder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ with-uuid = ["sqlx?/uuid", "sea-query/with-uuid", "uuid"]
with-time = ["sqlx?/time", "sea-query/with-time", "time"]
with-ipnetwork = ["sqlx?/ipnetwork", "sea-query/with-ipnetwork", "ipnetwork"]
with-mac_address = ["sqlx?/mac_address", "sea-query/with-mac_address", "mac_address"]
with-postgres-point = ["sea-query/with-postgres-point"]
postgres-array = ["sea-query/postgres-array"]
postgres-vector = ["sea-query/postgres-vector", "pgvector/sqlx"]
runtime-async-std = ["sqlx?/runtime-async-std"]
Expand Down
4 changes: 4 additions & 0 deletions sea-query-binder/src/sqlx_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ impl sqlx::IntoArguments<'_, sqlx::postgres::Postgres> for SqlxValues {
Value::MacAddress(mac) => {
let _ = args.add(mac.as_deref());
}
#[cfg(feature = "with-postgres-point")]
Value::Point(point) => {
let _ = args.add(point.as_deref());
}
#[cfg(feature = "postgres-array")]
Value::Array(ty, v) => match ty {
ArrayType::Bool => {
Expand Down
1 change: 1 addition & 0 deletions sea-query-postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ postgres-array = ["postgres-types/array-impls", "sea-query/postgres-array"]
postgres-vector = ["sea-query/postgres-vector", "pgvector/postgres"]
with-ipnetwork = ["postgres-types/with-cidr-0_2", "sea-query/with-ipnetwork", "ipnetwork", "cidr"]
with-mac_address = ["postgres-types/with-eui48-1", "sea-query/with-mac_address", "mac_address", "eui48"]
with-postgres-point = ["sea-query/with-postgres-point"]
2 changes: 2 additions & 0 deletions sea-query-postgres/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ impl ToSql for PostgresValue {
.map(|v| MacAddress::new(v.bytes()))
.to_sql(ty, out)
}
#[cfg(feature = "with-postgres-point")]
Value::Point(v) => v.as_deref().to_sql(ty, out),
}
}

Expand Down
1 change: 1 addition & 0 deletions src/backend/mysql/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ impl TableBuilder for MysqlQueryBuilder {
ColumnType::Inet => unimplemented!("Inet is not available in MySQL."),
ColumnType::MacAddr => unimplemented!("MacAddr is not available in MySQL."),
ColumnType::LTree => unimplemented!("LTree is not available in MySQL."),
ColumnType::Point => unimplemented!("Point is not available in MySQL."),
}
)
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions src/backend/postgres/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ impl TableBuilder for PostgresQueryBuilder {
ColumnType::MacAddr => "macaddr".into(),
ColumnType::Year => unimplemented!("Year is not available in Postgres."),
ColumnType::LTree => "ltree".into(),
ColumnType::Point => "point".into(),
}
)
.unwrap()
Expand Down
10 changes: 10 additions & 0 deletions src/backend/query_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,8 @@ pub trait QueryBuilder:
Value::Array(_, None) => write!(s, "NULL").unwrap(),
#[cfg(feature = "postgres-vector")]
Value::Vector(None) => write!(s, "NULL").unwrap(),
#[cfg(feature = "with-postgres-point")]
Value::Point(None) => s.write_str("NULL").unwrap(),
Value::Bool(Some(b)) => write!(s, "{}", if *b { "TRUE" } else { "FALSE" }).unwrap(),
Value::TinyInt(Some(v)) => write!(s, "{v}").unwrap(),
Value::SmallInt(Some(v)) => write!(s, "{v}").unwrap(),
Expand Down Expand Up @@ -1204,6 +1206,14 @@ pub trait QueryBuilder:
Value::IpNetwork(Some(v)) => write!(s, "'{v}'").unwrap(),
#[cfg(feature = "with-mac_address")]
Value::MacAddress(Some(v)) => write!(s, "'{v}'").unwrap(),
#[cfg(feature = "with-postgres-point")]
Value::Point(Some(v)) => {
s.write_str("'(").unwrap();
write!(s, "{}", v.x()).unwrap();
s.write_str(",").unwrap();
write!(s, "{}", v.y()).unwrap();
s.write_str(")'").unwrap();
}
};
s
}
Expand Down
1 change: 1 addition & 0 deletions src/backend/sqlite/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ impl SqliteQueryBuilder {
ColumnType::Bit(_) => unimplemented!("Bit is not available in Sqlite."),
ColumnType::VarBit(_) => unimplemented!("VarBit is not available in Sqlite."),
ColumnType::LTree => unimplemented!("LTree is not available in Sqlite."),
ColumnType::Point => unimplemented!("Point is not available in Sqlite."),
}
)
.unwrap()
Expand Down
2 changes: 2 additions & 0 deletions src/table/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub trait IntoColumnDef {
/// | Inet | N/A | inet | N/A |
/// | MacAddr | N/A | macaddr | N/A |
/// | LTree | N/A | ltree | N/A |
/// | Point | N/A | point | N/A |
#[non_exhaustive]
#[derive(Debug, Clone)]
pub enum ColumnType {
Expand Down Expand Up @@ -102,6 +103,7 @@ pub enum ColumnType {
Inet,
MacAddr,
LTree,
Point,
}

/// Length for var-char/binary; default to 255
Expand Down
18 changes: 18 additions & 0 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ use std::net::IpAddr;
#[cfg(feature = "with-mac_address")]
use mac_address::MacAddress;

#[cfg(feature = "with-postgres-point")]
use geo_types::Point;

use crate::{ColumnType, CommonSqlQueryBuilder, QueryBuilder, StringLen};

#[cfg(feature = "with-postgres-point")]
#[cfg_attr(docsrs, doc(cfg(feature = "with-postgres-point")))]
mod with_postgres_point;

/// [`Value`] types variant for Postgres array
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub enum ArrayType {
Expand Down Expand Up @@ -213,6 +220,9 @@ pub enum Value {
#[cfg(feature = "with-mac_address")]
#[cfg_attr(docsrs, doc(cfg(feature = "with-mac_address")))]
MacAddress(Option<Box<MacAddress>>),
#[cfg(feature = "with-postgres-point")]
#[cfg_attr(docsrs, doc(cfg(feature = "with-postgres-point")))]
Point(Option<Box<Point>>),
}

impl std::fmt::Display for Value {
Expand Down Expand Up @@ -400,6 +410,10 @@ impl Value {
#[cfg(feature = "with-mac_address")]
#[cfg_attr(docsrs, doc(cfg(feature = "with-mac_address")))]
Self::MacAddress(_) => Self::MacAddress(None),

#[cfg(feature = "with-postgres-point")]
#[cfg_attr(docsrs, doc(cfg(feature = "with-postgres-point")))]
Self::Point(_) => Self::Point(None),
}
}

Expand Down Expand Up @@ -504,6 +518,10 @@ impl Value {
#[cfg(feature = "with-mac_address")]
#[cfg_attr(docsrs, doc(cfg(feature = "with-mac_address")))]
Self::MacAddress(_) => Self::MacAddress(Some(Default::default())),

#[cfg(feature = "with-postgres-point")]
#[cfg_attr(docsrs, doc(cfg(feature = "with-postgres-point")))]
Self::Point(_) => Self::Point(Some(Box::new(Point::default()))),
}
}
}
Expand Down
36 changes: 36 additions & 0 deletions src/value/with_postgres_point.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use super::*;

pub use geo_types::Point;

impl From<Point> for Value {
fn from(x: Point) -> Value {
Value::Point(Some(Box::new(x)))
}
}

impl Nullable for Point {
fn null() -> Value {
Value::Point(None)
}
}

impl ValueType for Point {
fn try_from(v: Value) -> Result<Self, ValueTypeErr> {
match v {
Value::Point(Some(x)) => Ok(*x),
_ => Err(ValueTypeErr),
}
}

fn type_name() -> String {
stringify!(Point).to_owned()
}

fn array_type() -> ArrayType {
unimplemented!()
}

fn column_type() -> ColumnType {
ColumnType::Point
}
}