Skip to main content

clickhouse_kit/
lib.rs

1//! # smooai-clickhouse-kit (imports as `clickhouse_kit`)
2//!
3//! A safe-by-construction ClickHouse schema toolkit with two jobs:
4//!
5//! - **TS→Rust bridge** for developer-authored (static) tables: TypeScript owns
6//!   the schema; [`introspect`] reads the live ClickHouse back into Rust and
7//!   [`codegen`] emits `#[derive(Row)]` structs, with [`check_drift`](crate::drift)
8//!   asserting the Rust view ≡ the live DB. Rows stay Serde-native.
9//! - **Runtime toolkit** for user-defined / multi-tenant (dynamic) tables: an
10//!   allowlisted type system, identifier safety, DDL generation, [`flexible_table`],
11//!   forward-only migrations, and additive evolution — the safe-by-construction path
12//!   for turning untrusted customer input into SQL (that guarantee only counts in
13//!   the process holding the input, which is why this layer is canonical in Rust).
14//!
15//! See the repo `ROADMAP.md`.
16
17pub mod client;
18pub mod codegen;
19pub mod drift;
20pub mod evolve;
21pub mod flatten;
22pub mod flexible;
23pub mod introspect;
24pub mod migrate;
25pub mod safety;
26pub mod table;
27
28pub use client::{ChError, ChExecutor};
29pub use codegen::{
30    ch_type_to_rust, emit_insert_schema, emit_row_interface, emit_select_schema, emit_ts_module,
31    insert_schema_name, row_type_name, rust_row_struct, select_schema_name,
32};
33pub use drift::{check_drift, Drift, DriftResult};
34pub use evolve::{alter_add_columns_sql, diff_columns, ColumnDiff, LiveColumn};
35pub use flatten::{coerce_to_table, flatten_record, CoerceResult, FlattenOptions};
36pub use flexible::{flexible_table, FlexibleConfig};
37pub use introspect::{introspect_columns, introspect_row_struct};
38pub use migrate::{run_migrations, split_sql_statements, MigrationRunResult};
39pub use safety::{
40    assert_column_count, assert_not_reserved, quote_identifier, validate_identifier,
41    ColumnTypeSpec, DateTime64Spec, ScalarType, SchemaError, SchemaLimits, StringOnly,
42    DEFAULT_RESERVED_COLUMNS,
43};
44pub use table::{to_create_table_sql, ColumnSpec, IndexSpec, TableSpec, TtlMove, TtlSpec};