Comparing version 0.1.3 to 0.2.0
{ | ||
"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]) | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
25622
1
46