Extension for Diesel framework to support PostGIS types.
To ensure that the Geometry
type is in scope, read [this guide] and add use postgis_diesel::sql_types::*
to the import_types key in your diesel.toml
file.
Assume that the table is defined like this:
sql
CREATE EXTENSION IF NOT EXISTS postgis;
CREATE TABLE geometry_samples
(
id SERIAL PRIMARY KEY,
point geometry(Point,4326) NOT NULL,
linestring geometry(Linestring,4326) NOT NULL
);
Then Rust code may look like this: ```rust
extern crate diesel;
use postgisdiesel::operators::*; use postgisdiesel::types::*;
struct NewGeometrySample {
point: Point,
linestring: LineString
struct GeometrySample {
id: i32,
point: Point,
linestring: LineString
table! { use postgisdiesel::sqltypes::; use diesel::sql_types::; geometry_samples (id) { id -> Int4, point -> Geometry, linestring -> Geometry, } } ``` See integration test for more complete example.