uddl
v1.0.2
Published
universal data description language
Downloads
205
Readme
Universal Data Description Language
TypeScript <- UDDL -> SQL
|
v
json-schema
Example:
User {
id(primary_key auto_increment): int
name?: string
email(unique maxLength:255): string
gender(default:0 maximum:2): int
}
-> TypeScript
import {toTS} from 'uddl'
toTS(input)
export class User {
id: number
name?: string
email: string
gender: number = 0
}
-> SQL
import {toSQL} from 'uddl'
toSQL(input)
CREATE TABLE "user" (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
email TEXT UNIQUE NOT NULL,
gender INTEGER DEFAULT 0 NOT NULL
);
postgresql
toSQL(input, {flavor: 'postgresql'})
CREATE TABLE "user" (
id PRIMARY KEY BIGSERIAL,
name TEXT,
email VARCHAR(255) NOT NULL,
gender SMALLINT NOT NULL DEFAULT 0
);
-> json-schema
import {toJSONSchema} from 'uddl'
toJSONSchema(input)
{
"definitions": {
"User": {
"type": "object",
"properties": {
"email": {
"type": "string",
"maxLength": 255
},
"gender": {
"maximum": 2,
"type": "integer"
},
"id": {
"type": "integer"
},
"name": {
"type": "string"
}
},
"required": [ "id", "email", "gender" ]
}
}
}