1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//! PostgreSQL specific types

pub mod geometric;

pub mod sql_types {
    /// The PostgreSQL [Point](https://www.postgresql.org/docs/current/static/datatype-geometric.html) type.
    ///
    /// ### [`ToSql`](::diesel::serialize::ToSql) impls
    ///
    /// - [`PgPoint`](::pg::data_types::PgPoint)
    ///
    /// ### [`FromSql`](::diesel::deserialize::FromSql) impls
    ///
    /// - [`PgPoint`](::pg::data_types::PgPoint)
    ///
    ///
    /// # Examples
    ///
    /// ```rust
    /// # #![allow(dead_code)]
    /// # #[macro_use] extern crate diesel;
    /// # extern crate diesel_geometry;
    /// # include!("../../doctest_setup.rs");
    /// use diesel_geometry::data_types::PgPoint;
    ///
    ///
    /// table! {
    ///     use diesel::sql_types::*;
    ///     use diesel_geometry::sql_types::Point;
    ///     items {
    ///         id -> Integer,
    ///         name -> VarChar,
    ///         location -> Point,
    ///     }
    /// }
    ///
    /// # fn main() {
    /// #     use diesel::insert_into;
    /// #     use items::dsl::*;
    /// #     let connection = connection_no_data();
    /// #     connection.execute("CREATE TABLE items (
    /// #         id SERIAL PRIMARY KEY,
    /// #         name VARCHAR NOT NULL,
    /// #         location POINT NOT NULL
    /// #     )").unwrap();
    /// let inserted_location = insert_into(items)
    ///     .values((name.eq("Shiny Thing"), location.eq(PgPoint(3.1, 9.4))))
    ///     .returning(location)
    ///     .get_result(&connection);
    /// assert_eq!(Ok(PgPoint(3.1, 9.4)), inserted_location);
    /// # }
    /// ```
    #[derive(Debug, Clone, Copy, Default, QueryId, SqlType)]
    #[postgres(oid = "600", array_oid = "1017")]
    pub struct Point;

    /// The PostgreSQL [Box](https://www.postgresql.org/docs/current/static/datatype-geometric.html) type.
    ///
    /// ### [`ToSql`](::diesel::serialize::ToSql) impls
    ///
    /// - [`PgBox`](::pg::data_types::PgBox)
    ///
    /// ### [`FromSql`](::diesel::deserialize::FromSql) impls
    ///
    /// - [`PgBox`](::pg::data_types::PgBox)
    ///
    ///
    /// # Examples
    ///
    /// ```rust
    /// # #![allow(dead_code)]
    /// # #[macro_use] extern crate diesel;
    /// # extern crate diesel_geometry;
    /// # include!("../../doctest_setup.rs");
    /// use diesel_geometry::data_types::{PgPoint, PgBox};
    /// use diesel_geometry::sql_types;
    ///
    ///
    /// table! {
    ///     use diesel::sql_types::*;
    ///     use diesel_geometry::sql_types::Point;
    ///     items {
    ///         id -> Integer,
    ///         name -> VarChar,
    ///         location -> Point,
    ///     }
    /// }
    ///
    /// # fn main() {
    /// #     use diesel::insert_into;
    /// #     use diesel_geometry::prelude::*;
    /// #     use items::dsl::*;
    /// #     let connection = connection_no_data();
    /// #     connection.execute("CREATE TABLE items (
    /// #         id SERIAL PRIMARY KEY,
    /// #         name VARCHAR NOT NULL,
    /// #         location POINT NOT NULL
    /// #     )").unwrap();
    /// insert_into(items)
    ///     .values((name.eq("Shiny Thing"), location.eq(PgPoint(3.1, 9.4))))
    ///     .returning(location)
    ///     .execute(&connection)
    ///     .unwrap();
    /// let inserted_location = items
    ///     .select(location)
    ///     .filter(location.is_contained_by(
    ///         PgBox(PgPoint(0.,0.), PgPoint(10.,10.)).into_sql::<sql_types::Box>()
    ///     ))
    ///     .first(&connection);
    /// assert_eq!(Ok(PgPoint(3.1, 9.4)), inserted_location);
    /// # }
    /// ```
    #[derive(Debug, Clone, Copy, Default, QueryId, SqlType)]
    #[postgres(oid = "603", array_oid = "1020")]
    pub struct Box;

    /// The PostgreSQL [Circle](https://www.postgresql.org/docs/current/static/datatype-geometric.html) type.
    ///
    /// ### [`ToSql`](::diesel::serialize::ToSql) impls
    ///
    /// - [`PgCircle`](::pg::data_types::PgCircle)
    ///
    /// ### [`FromSql`](::diesel::deserialize::FromSql) impls
    ///
    /// - [`PgCircle`](::pg::data_types::PgCircle)
    ///
    ///
    /// # Examples
    ///
    /// ```rust
    /// # #![allow(dead_code)]
    /// # #[macro_use] extern crate diesel;
    /// # extern crate diesel_geometry;
    /// # include!("../../doctest_setup.rs");
    /// # use diesel_geometry::data_types::PgPoint;
    /// use diesel_geometry::data_types::PgCircle;
    ///
    ///
    /// table! {
    ///     use diesel::sql_types::*;
    ///     use diesel_geometry::sql_types::Circle;
    ///     items {
    ///         id -> Integer,
    ///         name -> VarChar,
    ///         location -> Circle,
    ///     }
    /// }
    ///
    /// # fn main() {
    /// #     use diesel::insert_into;
    /// #     use items::dsl::*;
    /// #     let connection = connection_no_data();
    /// #     connection.execute("CREATE TABLE items (
    /// #         id SERIAL PRIMARY KEY,
    /// #         name VARCHAR NOT NULL,
    /// #         location CIRCLE NOT NULL
    /// #     )").unwrap();
    /// let inserted_location = insert_into(items)
    ///     .values((name.eq("Shiny Thing"), location.eq(PgCircle(PgPoint(3.1, 6.6), 9.4))))
    ///     .returning(location)
    ///     .get_result(&connection);
    /// assert_eq!(Ok(PgCircle(PgPoint(3.1, 6.6), 9.4)), inserted_location);
    /// # }
    /// ```
    #[derive(Debug, Clone, Copy, Default, QueryId, SqlType)]
    #[postgres(oid = "718", array_oid = "719")]
    pub struct Circle;
}