@type-map-for/clickhouse
v0.1.1
Published
Compile-time TypeScript → ClickHouse field mapping
Readme
@type-map-for/clickhouse
Generate ClickHouse table schemas from TypeScript interfaces at compile time with template literal types.
Installation
npm install @type-map-for/clickhouseUsage
import type { ClickHouseSchema } from '@type-map-for/clickhouse';
interface Event {
id: string;
timestamp: number;
message?: string;
tags: string[];
metadata: { source: string };
}
type EventSchema = ClickHouseSchema<Event>;
// Result: Array<{
// { name: 'id'; type: 'String' }
// { name: 'timestamp'; type: 'Int32' | 'Float64' }
// { name: 'message'; type: 'Nullable(String)' }
// { name: 'tags'; type: 'Array(String)' }
// { name: 'metadata'; type: 'JSON' }
// }>
// Use with schema validation
const eventSchema: EventSchema = [
{ name: 'id', type: 'String' },
{ name: 'timestamp', type: 'Int32' },
{ name: 'message', type: 'Nullable(String)' },
{ name: 'tags', type: 'Array(String)' },
{ name: 'metadata', type: 'JSON' }
] as const satisfies EventSchema;Type Mapping
| TypeScript | ClickHouse |
|------------|------------|
| string | 'String' |
| number | 'Int32' | 'Float64' |
| boolean | 'Bool' |
| object | 'JSON' |
| T[] | 'Array(T)' (template literal) |
| T \| undefined | 'Nullable(T)' (template literal) |
Types
ChType<T>- ClickHouse type string for TypeScript typeTClickHouseField<T, K>- Schema field for propertyKof typeTClickHouseSchema<T>- Complete schema array for interfaceT
Contributing
Issues and pull requests welcome at github.com/nathancanine/type-map-for.
License
MIT
