Skip to content

samhuk/ts2psql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ts2psql

A script that converts Typescript type declarations into PostgreSQL CREATE TABLE scripts.

This is mainly useful for saving time when statements have to be created for a large number of types in your various projects.

NOTE: This is WIP. Current usage: go build && ./ts2psql (or go build && ts2psql if on Windows OS).

Usage

test.ts:

/* ts2psql { "tableName": "users" } */
export type User = {
  /* ts2psql { "primaryKey": true, "serial": true } */
  id: number
  /* ts2psql { "unique": true } */
  uuid: string
  /* ts2psql { "unique": true, "maxLength": 50 } */
  name: string
}
/* ts2psql end */

Add ts2psqlconfig.json configuration file:

{
  "include": ["*.ts"],
  "outFile": "./out.sql",
}

Run ts2psql

out.sql:

CREATE TABLE users (
  id serial PRIMARY KEY,
  uuid VARCHAR(50) UNIQUE NOT NULL,
  name VARCHAR(50) NOT NULL
);

About

Typescript type declaration to PostgreSQL CREATE TABLE converter

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published