| Crates.io | clickhouse-utils |
| lib.rs | clickhouse-utils |
| version | 0.2.2 |
| created_at | 2025-10-03 14:26:34.670989+00 |
| updated_at | 2025-10-08 07:37:38.6245+00 |
| description | Utilities for working with Clickhouse |
| homepage | |
| repository | https://github.com/GreeFine/clickhouse-utils |
| max_upload_size | |
| id | 1866768 |
| size | 53,595 |
Clickhouse Utils
This crate provides a set of utilities for working with Clickhouse.
create a migrations folder in your project and add your migrations files. Example:
migrations/
├── 0001_create_users_table.sql
└── 0002_add_email_column.sql
Run the migrations:
#[tokio::main]
async fn main() {
let client = clickhouse::Client::default()
.with_user("default")
.with_password("default")
.with_url("http://localhost:8123")
.with_database("default");
clickhouse_utils::migrate(&client).await.expect("failed to run migrations");
}
Serialize and Deserialize common types for Clickhouse.
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use fastnum::decimal::D256;
#[derive(Debug, Serialize, Deserialize, clickhouse::Row)]
pub struct SomeTable {
#[serde(with = "clickhouse_utils::serde::fastnum::Decimal::<25, {256 / 64}>")]
pub decimal: D256,
#[serde(with = "clickhouse_utils::serde::map")]
pub attributes: HashMap<String, String>,
}
For the decimal fastnum::D256, we use:
The database schema used:
CREATE TABLE clickhouse_utils (
decimal Decimal256(25),
attributes Map(String, String),
) ENGINE = MergeTree()
ORDER BY (decimal)