sfackler / rust-postgres

Native PostgreSQL driver for the Rust programming language
Apache License 2.0
3.49k stars 443 forks source link

impl ToSQL/FromSQL on url::Url #936

Closed nikhiljha closed 2 years ago

nikhiljha commented 2 years ago

I have a whole bunch of url::Url types in my structs, so here's a simple impl that renders it out as a TEXT string and back (this is probably the best/most interoperable way to implement it?)

My commit message is horrible so you'll want to squash/merge this if you decide this is something you want.

sfackler commented 2 years ago

I'm not sure about adding these impls. I want to avoid to the greatest extent possible conversions that only work for a subset of inputs.

nikhiljha commented 2 years ago

My impression was that all URLs (per the URL standard) can be represented as a string. Unless you mean inputs == what's in the database, but doesn't it seem reasonable to expect errors if you set your type to url::Url and then try to read a db column that has non-URLs?

notgull commented 2 years ago

I think it would be better to have a conversion to a struct that uses String instead of Url. Is there a way to do that listlessly within the url crate?

sfackler commented 2 years ago

Yes, there are many values of strings that can be stored in the database that are not valid URLs.

nikhiljha commented 2 years ago

Okay so it looks like the URL crate is mappable to pguri, but I'm guessing you don't want to support postgres extensions from this crate.

In that case, thanks for your time! I'll close this.