#gis #geo #diesel #post-gis

postgis_diesel

An extension for Diesel framework to support PostGIS geometry datatype

4 releases (breaking)

0.4.0 Jun 12, 2022
0.3.0 Feb 27, 2022
0.2.0 Oct 17, 2021
0.1.0 Feb 21, 2021

#102 in Math

Download history 2301/week @ 2022-06-11 1648/week @ 2022-06-18 1974/week @ 2022-06-25 1428/week @ 2022-07-02 2170/week @ 2022-07-09 2571/week @ 2022-07-16 647/week @ 2022-07-23 676/week @ 2022-07-30 555/week @ 2022-08-06 508/week @ 2022-08-13 628/week @ 2022-08-20 561/week @ 2022-08-27 563/week @ 2022-09-03 800/week @ 2022-09-10 872/week @ 2022-09-17 1106/week @ 2022-09-24

3,459 downloads per month

MIT license

15KB
232 lines

PostGIS Diesel

Extension for Diesel framework to support PostGIS types. The library is simple extension of rust-postgis

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:

#[derive(Insertable)]
#[table_name = "geometry_samples"]
struct NewGeometrySample {
    point: PointC<Point>,
    linestring: LineStringC<LineStringT<Point>>,
}

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

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

Dependencies

~5MB
~131K SLoC