#mysql #diesel #gis #geospatial #geo

diesel-mysql-spatial

An extension for the Diesel framework to support MySQL spatial datatypes

3 releases

0.1.2 May 17, 2022
0.1.1 May 16, 2022
0.1.0 May 16, 2022

#1837 in Database interfaces

MPL-2.0 and AGPL-3.0+

41KB
754 lines

diesel-mysql-spatial - An extension for the Diesel framework to support MySQL spatial datatypes

Crates.io Documentation License

Usage

  1. Add the following to your Cargo.toml:
[dependencies]
diesel-mysql-spatial = "0.1"
  1. Read the crate documentation

Example

Assuming a MySQL table defined like this

CREATE TABLE districts (
    id         INTEGER NOT NULL PRIMARY KEY,
    center     POINT NOT NULL,
    area       POLYGON NOT NULL
);

then the Rust code may look like this:

use diesel_mysql_spatial::data_types::{Point, Polygon};

#[derive(Insertable, Queryable)]
#[table_name = "districts"]
struct District {
    id: i32,
    center: Point,
    area: Polygon,
}

table! {
    use diesel_mysql_spatial::sql_types::*;
    use diesel::sql_types::*;
    districts (id) {
        id -> Integer,
        center -> Point,
        area -> Polygon,
    }
}

Stability

This crate follows semantic versioning with the additional promise that below 1.0.0 backwards-incompatible changes will not be introduced with only a patch-level version number change.

License

Licensed under Mozilla Public License, Version 2.0 (LICENSE or https://www.mozilla.org/en-US/MPL/2.0/).

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, shall be licensed as above including compatibility with secondary licenses, as defined by the MPL.

Dependencies

~8MB
~222K SLoC