postgres-iots-codegen

0.4.0 • Public • Published

postgres-iots-codegen

Command line utility that generates io-ts contracts from postgresql database schema.

How to use

Type in your console npx pgiotsgen --help to get help:

Generates io-ts contracts from postgresql database schema.
 
Usage:
  pgiotsgen --host=<host> [--port=<port>] --username=<username> --password=<password> --database=<database> --outdir=<outdir> [--capital] [--nosuffix] [--index] [--ignore=<tables>] [--enum]
  pgiotsgen --help
 
Options:
  --help                      Show this screen.
  -h --host=<host>            Specifies the host name of the machine on which the server is running. 
  -p --port=<port>            Specifies the TCP port on which the server is listening for connections.
  -u --username=<username>    User name to connect as.
  -w --password=<password>    Password used to connect.
  -d --database=<database>    Database name to connect to.
  -o --outdir=<outdir>        Directory to generate contracts to.
  -i --index                  Also generate root index.ts file for generated contracts.
  -c --capital                Name contract files with a capital letter.
  -s --nosuffix               Don't append contract file names with "Contract" suffix.
  -t --ignore=<tables>        Comma separated list of tables that should be ignored.
  -e --enum                   Create enum with table names inside the index file (if --index specified)

Example of produced contract file

import * as t from "io-ts";
 
export const UsersEntityContract = t.interface({
  id: t.number, // integer nullable: NO
  name: t.string, // character varying nullable: NO
  email: t.string, // character varying nullable: NO
  token: t.string, // character varying nullable: NO
});
 
export type IUsersEntity = t.TypeOf<typeof UsersEntityContract>;

Readme

Keywords

none

Package Sidebar

Install

npm i postgres-iots-codegen

Weekly Downloads

0

Version

0.4.0

License

MIT

Unpacked Size

10.9 kB

Total Files

9

Last publish

Collaborators

  • pldin601