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")]
40impl Expressive<crate::mysql::types::AnyMysqlType> for Point {
41 fn expr(&self) -> Expression<crate::mysql::types::AnyMysqlType> {
42 Expression::new(
43 format!(
44 "ST_GeomFromText('POINT({} {})', {})",
45 self.x, self.y, self.srid
46 ),
47 vec![],
48 )
49 }
50}
51
52#[cfg(feature = "postgres")]
55impl Expressive<crate::postgres::types::AnyPostgresType> for Point {
56 fn expr(&self) -> Expression<crate::postgres::types::AnyPostgresType> {
57 Expression::new(
58 format!(
59 "ST_SetSRID(ST_MakePoint({}, {}), {})",
60 self.x, self.y, self.srid
61 ),
62 vec![],
63 )
64 }
65}
66
67#[cfg(feature = "sqlite")]
70impl Expressive<crate::sqlite::types::AnySqliteType> for Point {
71 fn expr(&self) -> Expression<crate::sqlite::types::AnySqliteType> {
72 Expression::new(
73 format!("MakePoint({}, {}, {})", self.x, self.y, self.srid),
74 vec![],
75 )
76 }
77}