ClickHouse / clickhouse-rs

Official pure Rust typed client for ClickHouse DB
https://clickhouse.com
Apache License 2.0
315 stars 87 forks source link

Please add support for `chrono::{Date, DateTime}` and friends in addition to "time". #105

Open keltia opened 5 months ago

keltia commented 5 months ago

After wrestling a bit with clickhouse_rs to extract dates out of a CH table, I find out it is using types from the "time" crate. It would be nice to have support for the different types from the "chrono" crate as well, I find the latter much easier to use.

Have a chrono feature for example, serde already know how to deal with these.

Having

#[derive(Debug, Deserialize, Serialize, Row)]
pub struct Install {
    pub id: u32,
    pub site_id: u32,
    pub antenna_id: u32,
    pub start_at: DateTime<Utc>,
    pub end_at: DateTime<Utc>,
    pub comment: String,
}

would be way easier than my current

#[derive(Debug, Deserialize, Serialize, Row)]
pub struct Install {
    pub id: u32,
    pub site_id: u32,
    pub antenna_id: u32,
    #[serde(with = "clickhouse::serde::time::datetime")]
    pub start_at: OffsetDateTime,
    #[serde(with = "clickhouse::serde::time::datetime")]
    pub end_at: OffsetDateTime,
    pub comment: String,
}

Thanks.

v3xro commented 3 months ago

There's also the jiff crate now as well. Would be happy to contribute support

loyd commented 2 months ago

This crate should support all three under features, so I'd like to accept PR. Anyway, I'm thinking about moving to jiff for my production code so that it will be implemented eventually anyway