Socket
Book a DemoInstallSign in
Socket

database-types

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

database-types

A generic type generator for various databases.

Source
npmnpm
Version
1.0.3
Version published
Weekly downloads
8
-27.27%
Maintainers
1
Weekly downloads
 
Created
Source

database-types

Travis build status Coveralls NPM version Canonical Code Style Twitter Follow

A generic type generator for various databases.

The current supported database backend is Postgres. Track #1 issue for MySQL support.

Use case

If you are developing applications in JavaScript and using either of the strict type systems, then you can use database-types to generate types describing the database.

Example usage

Generating Flow types

export DATABASE_TYPES_DATABASE_CONNECTION_URI=postgres://postgres:password@127.0.0.1/test
export DATABASE_TYPES_COLUMN_FILTER="return !['raster_overviews', 'raster_columns', 'geometry_columns', 'geography_columns', 'spatial_ref_sys'].includes(tableName)"
export DATABASE_TYPES_DIALECT=flow

database-types generate > ./types.js

This generates file containing Flow type declarations in the following format:

export type ReservationSeatRecordType = {|
  +createdAt: string,
  +id: number,
  +reservationId: number,
  +seatId: number
|};

export type TicketTypeRecordType = {|
  +cinemaId: number,
  +id: number,
  +name: string,
  +nid: string,
  +policy: string | null
|};

// ...

CLI

npm install database-types -g

Options:
  --help                        Show help                              [boolean]
  --column-filter               Function used to filter columns. Function is
                                constructed using `new Function`. Function
                                receives table name as the first parameter and
                                column name as the second parameter (parameter
                                names are "tableName" and "columnName").[string]
  --property-name-formatter     Function used to format property name. Function
                                is constructed using `new Function`. Function
                                receives column name as the first parameter
                                (parameter name is "columnName"). The default
                                behaviour is to (lower) camelCase the column
                                name.                                   [string]
  --type-name-formatter         Function used to format type name. Function is
                                constructed using `new Function`. Function
                                receives table name as the first parameter
                                (parameter name is "tableName"). The default
                                behaviour is to (upper) CamelCase the table name
                                and suffix it with "RecordType".        [string]
  --database-connection-uri                                           [required]
  --dialect                                         [required] [choices: "flow"]
  --include-materialized-views                         [boolean] [default: true]

Keywords

flowtype

FAQs

Package last updated on 06 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts