#gis #diesel #post-gis

postgis_diesel

An extension for Diesel framework to support PostGIS geometry datatype

10 releases (6 stable)

2.2.1 Jul 16, 2023
2.1.0 Jan 27, 2023
2.0.0 Dec 18, 2022
1.1.0 Oct 23, 2022
0.1.0 Feb 21, 2021

#10 in Geospatial

Download history 3290/week @ 2023-06-01 4741/week @ 2023-06-08 3468/week @ 2023-06-15 5397/week @ 2023-06-22 4163/week @ 2023-06-29 5091/week @ 2023-07-06 5321/week @ 2023-07-13 7880/week @ 2023-07-20 5502/week @ 2023-07-27 5914/week @ 2023-08-03 4484/week @ 2023-08-10 4928/week @ 2023-08-17 4998/week @ 2023-08-24 4942/week @ 2023-08-31 5604/week @ 2023-09-07 4622/week @ 2023-09-14

21,013 downloads per month

MIT license

115KB
3K SLoC

PostGIS Diesel

Extension for Diesel framework to support PostGIS types.

Example of Usage

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:

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:

#[macro_use]
extern crate diesel;

use postgis_diesel::operators::*;
use postgis_diesel::types::*;

#[derive(Insertable)]
#[diesel(table_name = geometry_samples)]
struct NewGeometrySample {
    point: Point,
    linestring: LineString<Point>,
}

#[derive(Queryable)]
struct GeometrySample {
    id: i32,
    point: Point,
    linestring: LineString<Point>,
}

table! {
    use postgis_diesel::sql_types::*;
    use diesel::sql_types::*;
    geometry_samples (id) {
        id -> Int4,
        point -> Geometry,
        linestring -> Geometry,
    }
}

See integration test for more complete example.

How to Run Tests

  1. Start Postgis DB
docker compose up
  1. Run tests
cargo test

Dependencies

~3MB
~56K SLoC