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 - npm Package Compare versions

Comparing version 0.1.3 to 0.2.0

3

package.json
{
"name": "chvalid",
"version": "0.1.3",
"version": "0.2.0",
"description": "Define schema validation for most common usage cases",

@@ -19,3 +19,2 @@ "main": "lib/index.js",

"scripts": {
"test": "echo \"Error: no test specified\" && exit 0",
"build": "rm -rf lib && tsc"

@@ -22,0 +21,0 @@ },

@@ -1,1 +0,46 @@

# chvalid
# 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
```js
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
```js
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])
```
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