#postgis #diesel #gis

postgis_diesel

An extension for Diesel framework to support PostGIS geometry datatype

13 releases (stable)

2.3.1 Apr 6, 2024
2.3.0 Jan 7, 2024
2.2.1 Jul 16, 2023
2.1.0 Jan 27, 2023
0.1.0 Feb 21, 2021

#108 in Database interfaces

Download history 2027/week @ 2023-12-31 3829/week @ 2024-01-07 4131/week @ 2024-01-14 4005/week @ 2024-01-21 4208/week @ 2024-01-28 3276/week @ 2024-02-04 4517/week @ 2024-02-11 3223/week @ 2024-02-18 3564/week @ 2024-02-25 3847/week @ 2024-03-03 2821/week @ 2024-03-10 2688/week @ 2024-03-17 2928/week @ 2024-03-24 3831/week @ 2024-03-31 2866/week @ 2024-04-07 4187/week @ 2024-04-14

13,926 downloads per month

MIT license

120KB
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 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
~57K SLoC