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
}
import {toTS} from 'uddl'
toTS(input)
export class User {
id: number
name?: string
email: string
gender: number = 0
}
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
);
toSQL(input, {flavor: 'postgresql'})
CREATE TABLE "user" (
id PRIMARY KEY BIGSERIAL,
name TEXT,
email VARCHAR(255) NOT NULL,
gender SMALLINT NOT NULL DEFAULT 0
);
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" ]
}
}
}