use vantage_expressions::{Expression, Expressive};
#[derive(Debug, Clone)]
pub struct Point {
x: f64,
y: f64,
srid: i32,
}
impl Point {
pub fn new(x: f64, y: f64) -> Self {
Self { x, y, srid: 0 }
}
pub fn srid(mut self, srid: i32) -> Self {
self.srid = srid;
self
}
}
#[cfg(feature = "mysql")]
impl Expressive<crate::mysql::types::AnyMysqlType> for Point {
fn expr(&self) -> Expression<crate::mysql::types::AnyMysqlType> {
Expression::new(
format!(
"ST_GeomFromText('POINT({} {})', {})",
self.x, self.y, self.srid
),
vec![],
)
}
}
#[cfg(feature = "postgres")]
impl Expressive<crate::postgres::types::AnyPostgresType> for Point {
fn expr(&self) -> Expression<crate::postgres::types::AnyPostgresType> {
Expression::new(
format!(
"ST_SetSRID(ST_MakePoint({}, {}), {})",
self.x, self.y, self.srid
),
vec![],
)
}
}
#[cfg(feature = "sqlite")]
impl Expressive<crate::sqlite::types::AnySqliteType> for Point {
fn expr(&self) -> Expression<crate::sqlite::types::AnySqliteType> {
Expression::new(
format!("MakePoint({}, {}, {})", self.x, self.y, self.srid),
vec![],
)
}
}