chvalid by @bytadaniel
A simple utility to generate datatype schemas for Clickhouse and validate incoming rows
Create model from schema and validate rows to insert query
import { UInt32, String, Map } from './src/types'
import { Schema } from './src/schema'
import { model } from './src/model'
const developerSchema = new Schema({
age: new UInt32({ default: -1 }),
name: new String({ default: 'john doe' }),
skills: new Map()
})
type IDeveloper = {
age: number,
name: string,
skills: Record<string, string>
}
const DeveloperModel = model<IDeveloper>(developerSchema, 'database', 'table')
console.log(DeveloperModel.$getCreateQuery())
DeveloperModel.$createInsertQuery([
{
age: Infinity,
name: null,
}
])
🔥 Killer feature
Create models automaticly from DDL
import { modelFromCreateQuery } from './src/helpers/model-from-create-query'
const ddl = `CREATE TABLE database.table (age UInt32, name String, ...)`
const DeveloperModel = modelFromCreateQuery(ddl)
DeveloperModel.$createInsertQuery([...rows])