-
-
Notifications
You must be signed in to change notification settings - Fork 458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support geo types with georust/geo #245
Conversation
While implementing this, I had another idea; either an alternative or an additional implementation for geo types. The geo types could be supported via tuples (eg. let lat: f64 = 40.018782;
let lng: f64 = -105.278201;
db.execute("INSERT INTO places (loc) VALUES ($1)", &[(&lat, &lng)]) The type mappings using tuples COULD be:
|
Thanks! Could you add some tests? See here for reference: https://github.com/sfackler/rust-postgres/tree/master/postgres/tests/types |
return Err("invalid message length".into()); | ||
} | ||
|
||
// let _ = types::bool_from_sql(&raw[0..1])?; // is path open or closed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it going to be problematic that we're discarding this information?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will not cause a database error to occur.
To recover this information, a user would need to SELECT
the value of isopen(mypath)
.
The more interesting part of the issue is with ToSql
where there are two different ways to create a path: an open path path '[(1,2),(3,4)]'
and a closed path path '((1,2),(3,4))'
. The PR handles this by always inserting an open path. To insert a closed path, you would need to write pclose($1)
and let Postgres flip that bit during statement evaluation. This behavior is documented in the README.
I opted for that behavior because:
- The Polygon type is already very similar to a Closed path (see https://www.postgresql.org/docs/9.2/static/datatype-geometric.html#DATATYPE-GEO-TABLE)
- A LineString is treated like an Open path in most uses
Thanks! |
This pull request implements part of #244. Supporting the default postgres geographic types with https://github.com/georust/rust-geo.
The types LINE and LSEG haven't been implemented yet because there is no obvious mapping in the current implementation of the geo crate. I hope to discuss this with the maintainer of that crate.