[go: up one dir, main page]

postgis/
lib.rs

1//
2// Copyright (c) ShuYu Wang <andelf@gmail.com>, Feather Workshop and Pirmin Kalberer. All rights reserved.
3//
4
5//! An extension to rust-postgres, adds support for PostGIS.
6//!
7//! - PostGIS type helper
8//! - GCJ02 support (used offically in Mainland China)
9//! - Tiny WKB (TWKB) support
10//!
11//! ```rust,no_run
12//! use postgres::{Client, NoTls};
13//! use postgis::{ewkb, LineString};
14//!
15//! fn main() {
16//!     let mut client = Client::connect("host=localhost user=postgres", NoTls).unwrap();
17//!     for row in &client.query("SELECT * FROM busline", &[]).unwrap() {
18//!         let route: ewkb::LineString = row.get("route");
19//!         let last_stop = route.points().last().unwrap();
20//!         let _ = client.execute("INSERT INTO stops (stop) VALUES ($1)", &[&last_stop]);
21//!     }
22//! }
23//! ```
24//!
25//! Handling NULL values:
26//!
27//! ```rust,no_run
28//! # use postgres::{Client, NoTls};
29//! # use postgis::{ewkb, LineString};
30//! # let mut client = Client::connect("host=localhost user=postgres", NoTls).unwrap();
31//! # let rows = client.query("SELECT * FROM busline", &[]).unwrap();
32//! # let row = rows.first().unwrap();
33//! let route = row.try_get::<_, Option<ewkb::LineString>>("route");
34//! match route {
35//!     Ok(Some(geom)) => { println!("{:?}", geom) }
36//!     Ok(None) => { /* Handle NULL value */ }
37//!     Err(err) => { println!("Error: {}", err) }
38//! }
39//! ```
40
41pub mod error;
42mod types;
43pub use types::{LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon};
44pub mod ewkb;
45pub mod mars;
46mod postgis;
47pub mod twkb;