vantage_sql/primitives/
point.rs1use vantage_expressions::{Expression, Expressive};
2
3#[derive(Debug, Clone)]
19pub struct Point {
20 x: f64,
21 y: f64,
22 srid: i32,
23}
24
25impl Point {
26 pub fn new(x: f64, y: f64) -> Self {
28 Self { x, y, srid: 0 }
29 }
30
31 pub fn srid(mut self, srid: i32) -> Self {
32 self.srid = srid;
33 self
34 }
35}
36
37#[cfg(feature = "mysql")]
38impl Expressive<crate::mysql::types::AnyMysqlType> for Point {
39 fn expr(&self) -> Expression<crate::mysql::types::AnyMysqlType> {
40 Expression::new(
41 format!(
42 "ST_GeomFromText('POINT({} {})', {})",
43 self.x, self.y, self.srid
44 ),
45 vec![],
46 )
47 }
48}
49
50#[cfg(feature = "postgres")]
51impl Expressive<crate::postgres::types::AnyPostgresType> for Point {
52 fn expr(&self) -> Expression<crate::postgres::types::AnyPostgresType> {
53 Expression::new(
54 format!(
55 "ST_SetSRID(ST_MakePoint({}, {}), {})",
56 self.x, self.y, self.srid
57 ),
58 vec![],
59 )
60 }
61}
62
63#[cfg(feature = "sqlite")]
64impl Expressive<crate::sqlite::types::AnySqliteType> for Point {
65 fn expr(&self) -> Expression<crate::sqlite::types::AnySqliteType> {
66 Expression::new(
67 format!("MakePoint({}, {}, {})", self.x, self.y, self.srid),
68 vec![],
69 )
70 }
71}