georust / geocoding

Geocoding library for Rust.
https://crates.io/crates/geocoding
Apache License 2.0
76 stars 19 forks source link

Permit serialization of responses #31

Closed terry90 closed 4 years ago

terry90 commented 4 years ago

It makes it easier to store.

Here is a code example with diesel:

use chrono::NaiveDateTime;
use diesel_as_jsonb::AsJsonb;
use geocoding::opencage::Results as OpenCageResult;
use geocoding::openstreetmap::OpenstreetmapResult as OSMResult;
use uuid::Uuid;

use crate::schema::locations;

#[derive(Serialize, Deserialize, Debug, AsJsonb)]
pub enum LocationData {
    OSM(OSMResult<f64>),
    OpenCage(OpenCageResult<f64>),
}

#[derive(Queryable)]
pub struct Location {
    pub id: Uuid,
    pub provider: String,
    pub data: LocationData,
    pub label: String,
    pub lat: f64,
    pub lon: f64,
    pub created_at: NaiveDateTime,
    pub updated_at: NaiveDateTime,
}

#[derive(Insertable)]
#[table_name = "locations"]
pub struct NewLocation {
    pub provider: String,
    pub data: LocationData,
    pub label: String,
    pub lat: f64,
    pub lon: f64,
}
urschrei commented 4 years ago

This looks useful and uncontroversial to me. Could you also update CHANGES before we merge?

terry90 commented 4 years ago

Sure, should I add an entry 0.1.1 to the file ? Edit: done, I've checked the current version, 0.1.3, so I added a 0.1.4. Feel free to change this

urschrei commented 4 years ago

Thanks!

urschrei commented 4 years ago

bors r+

bors[bot] commented 4 years ago

Build failed

urschrei commented 4 years ago

bors retry

bors[bot] commented 4 years ago

Build succeeded

urschrei commented 4 years ago

This ended up as part of 0.2.0 btw – now on crates.io.

terry90 commented 4 years ago

Nice, thank you

Le ven. 10 avr. 2020 à 17:57, Stephan Hügel notifications@github.com a écrit :

This ended up as part of 0.2.0 btw – now on crates.io.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/georust/geocoding/pull/31#issuecomment-612094028, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOZ5J4HQFNN32G3INLZXDDRL46WRANCNFSM4MBC4AUQ .