uddl

1.0.2 • Public • Published

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" ]
    }
  }
}

Package Sidebar

Install

npm i uddl

Weekly Downloads

3

Version

1.0.2

License

ISC

Unpacked Size

30.6 kB

Total Files

14

Last publish

Collaborators

  • zf