1.0.2 • Published 2 years ago

sqema v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

When you create a web application, you need to validate client-side inputs, most of inputs are same as database fields and you need to create validation schema manually. With sqema you can automatically export your sql tables to json-schema format.

Installation

npm install sqema

Usage

In scripts

import SQLToJsonSchemaConvertor from 'sqema';

const convertor = new SQLToJsonSchemaConvertor(
    'postgres', 
    { host: 'localhost', port: 5432, database: '***', username: '***', password: '***'}
);

convertor.generateJsonSchemas()
    .then(() => {
        // This will write json schemas to output directory
        convertor.writeJsonSchemas('output', 'single-file', 'json');
    });

writeJsonSchemas Options

OptionDescriptionPossible valuesDefault value
pathPath of a directory to write schemasAny stringoutput
granularityScale of data to be writtensingle-file: Write all schemas in single file schema: Write each schema in separate files table: Write each table in separate file field: Write each field in separate filesingle-file
formatFormat of outputjson js tsjson

Using cli

You can use sqma command with following options:

Options:
  -d, --dialect <dialect>          database dialect (choices: "postgres", default: "postgres")
  -h, --host <host>                database host
  -port, --port <port>             database port
  -db, --database <database>       database name
  -u, --username <username>        database username
  -p, --path <path>                output folder (default: "output")
  -g, --granularity <granularity>  output files granularity (choices: "single-file", "schema", "table", "field", default: "single-file")
  -f, --format <format>            output format (choices: "json", "js", "ts", default: "json")
  --help                           display help for command

Note

This library currently supports postgresql database and also some complex data types not implemented yet.