Skip to content
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

serde_json::to_string serialize uuid type into string #73

Open
wexgjduv opened this issue Jul 6, 2023 · 0 comments · May be fixed by #76
Open

serde_json::to_string serialize uuid type into string #73

wexgjduv opened this issue Jul 6, 2023 · 0 comments · May be fixed by #76

Comments

@wexgjduv
Copy link

wexgjduv commented Jul 6, 2023

Hi, below is my struct definition for uuid_test table:

#[derive(Debug, Serialize, Deserialize, Row)]
pub struct Test {
    #[serde(with = "clickhouse::serde::uuid")]
    pub uuid: Uuid,
    pub name: String,
}

pub async fn create_table(client: &Client) -> Result<(), Box<dyn std::error::Error>> {
    client
        .query(
            "
            CREATE TABLE IF NOT EXISTS uuid_test(
                uuid UUID,
                name LowCardinality(String)
            )
            ENGINE = MergeTree
            ORDER BY name
        ",
        )
        .execute()
        .await
        .map_err(|err: Error| err.into())
}


pub async fn get_by_uuid(client: &Client, uuid: &Uuid) -> Result<Test, Box<dyn std::error::Error>> {
    let test = client
        .query("SELECT ?fields FROM uuid_test WHERE uuid = ?")
        .bind(uuid)
        .fetch_one::<Test>()
        .await?;

    println!("[debug]Got test: {test:#?}");

    Ok(test)
}

I used serde_json to serialize Test into string but uuid was output in array type:

let uuid = "...";
let test = get_by_uuid(&db, &uuid).await.unwrap();
let s = serde_json::to_string(&test).unwrap();
println(s);

Here is the output:

{"uuid":[214,64,245,20,199,106,26,34,103,164,208,2,209,231,100,162],"name":"Test"}

How could I serialize uuid into string type?

Thanks

@wexgjduv wexgjduv changed the title serd_json::to_string serialize uuid type into string serde_json::to_string serialize uuid type into string Jul 6, 2023
fky2015 added a commit to fky2015/clickhouse.rs that referenced this issue Jul 11, 2023
UUID should be serialize into a more human-readable format
when working with JSON.
This commit fixes loyd#73.
fky2015 added a commit to fky2015/clickhouse.rs that referenced this issue Jul 11, 2023
UUID should be serialized into a more human-readable format
when working with JSON.
This commit fixes loyd#73.
@fky2015 fky2015 linked a pull request Jul 11, 2023 that will close this issue
fky2015 added a commit to fky2015/clickhouse.rs that referenced this issue Oct 6, 2023
UUID should be serialized into a more human-readable format
when working with JSON.
This commit fixes loyd#73.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant