Skip to content

Postgis types extension for Diesel framework

License

Notifications You must be signed in to change notification settings

Plunts/postgis-diesel

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Postgis types extension for Diesel framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 99.9%
  • Shell 0.1%