Skip to content
Generate Typescript types from Postgres
JavaScript TypeScript
Branch: master
Clone or download

Latest commit

Latest commit 30920f6 May 24, 2020


Type Name Latest commit message Commit time
Failed to load latest commit information.
bin Initial commit Feb 18, 2020
build Bump version May 24, 2020
example Update example May 24, 2020
src Bump version May 24, 2020
LICENSE Initial commit Feb 18, 2020
package.json Bump version May 24, 2020
tsconfig.json Fix package.json and doc issues Feb 23, 2020
yarn.lock Merge branch 'master' of Apr 21, 2020


Generate Typescript types from a live database

Works with Postgres databases.


Install with:

$ npm i -g kanel

To run, make sure you are in a folder that has a .kanelrc.js configuration file, and type:

$ kanel


Here is an example configuration file:

const path = require('path');

module.exports = {
  connection: {
    host: 'localhost',
    user: 'postgres',
    password: 'postgres',
    database: 'acme',

  filenameCasing: 'dash',
  sourceCasing: 'snake',
  preDeleteModelFolder: true,

  customTypeMap: {
    tsvector: 'string',
    bpchar: 'string',

  schemas: [
      name: 'public',
      ignore: ['knex_migrations', 'knex_migrations_lock'],
      modelFolder: path.join(__dirname, 'src', 'models'),

The configuration file contains the following fields:

connection (Required)

This is the database connection object. It follows the client constructor in pg. As you will typically want to run Kanel on your development machine, you probably want a simple localhost connection as in the example above.


Specifies how you like your files cased. Can be any of the recase options: dash, snake, camel or pascal. Default is pascal which means your generated files will have filenames that look like this: UserProfile.ts.


Specifies what the casing of your database entities are. The standard is for entities to be snake cased, so the default is snake but if you for any reason use another convention, you can specify it here.


Delete the model folder before generating files? Set this to true if you want to make sure that there are no deprecated models in your model folder after running Kanel. Defaults to false.


This allows you to specify (or override) which types to map to. Kanel recognizes the most common types and applies the most likely Typescript type to it, but you might want to override this. This map maps from postgres type to typescript type.


This is an array of schemas to process. These contain the following fields:

Name of the schema.


Folder on disk where the models will be stored. Note that if preDeleteModelFolder above is set, this folder will be deleted and recreated when Kanel is run.


An array of tables and views to ignore. Use this if there are things in your database you don't care to generate models for like migration information etc.


To see an example of the result, check out the /example folder. It uses the Sample Database from

Kanel will scan tables, views and enum types. It will generate a model type for each table and view. Additionally, it will create an initializer type for tables that aren't tagged @fixed in the comment. Initializer types represent the requirements for creating a new row in the table. Columns that are nullable or have default values are considered optional.

Documentation is extracted from postgres comments on your tables, columns etc., as jsdoc. For more info about postgres comments, see:

You can’t perform that action at this time.