clickhouse.rs icon indicating copy to clipboard operation
clickhouse.rs copied to clipboard

Insert a DateTime Type

Open 0x003e opened this issue 4 years ago • 1 comments

Hi everyone,

Thank you for this librarie.

I want to insert some DateTime in a field:

CREATE TABLE IF NOT EXISTS a.test
(
       `key`           String,
       `test`           DateTime
) ENGINE = MergeTree() ORDER BY (key) SETTINGS index_granularity = 8192;
use chrono::{DateTime};
use chrono_tz::Tz;
use reflection::{terminal, Type};
use serde::{Deserialize, Serialize};
use clickhouse::{Client, Reflection};

#[derive(Debug, Reflection, Serialize, Deserialize)]
struct Row{
    key: String,
    test: DateTime<Utc>,
}

let timestamp= chrono::offset::Utc::now();
insert.write(&Row{
   key: "key".to_string(),
   test: timestamp,
 });
let stats = insert.commit().await?;

however, when commit is called

insert.commit().await?;

I have this error:

error[E0277]: the trait bound `chrono::DateTime<chrono::Utc>: clickhouse::Reflection` is not satisfied
   --> src/main.rs:116:17
    |
116 | #[derive(Debug, Reflection, Serialize, Deserialize)]
    |                 ^^^^^^^^^^ the trait `clickhouse::Reflection` is not implemented for `chrono::DateTime<chrono::Utc>`
    |
    = note: required by `clickhouse::Reflection::ty`
    = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

How to insert a DateTime ?

0x003e avatar Dec 08 '20 02:12 0x003e

I found: u32

0x003e avatar Dec 08 '20 03:12 0x003e