Socket
Socket
Sign inDemoInstall

chvalid

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chvalid

Define schema validation for most common usage cases


Version published
Weekly downloads
5
Maintainers
1
Weekly downloads
 
Created
Source

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()) // CREATE TABLE IS NOT EXISTS ...

DeveloperModel.$createInsertQuery([
	{
		age: Infinity, // Infonoty is not valid - error
		name: null, // type is not string - error
		// skills is not defined - error
	}
]) // INSERT INTO database.table (age UInt32 DEFAULT -1, name String DEFAULT 'john doe' ...

🔥 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])

Keywords

FAQs

Package last updated on 10 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc