chrislse / schemats

Generate TypeScript interface definitions from SQL database schema

Home Page:https://www.npmjs.com/package/schemats

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

schemats

This is a personal fork of PYST/schemats, which is a fork of SweetIQ/schemats.

Usage:

git clone https://github.com/danvk/schemats.git
cd schemats
npm install
npm run build

node bin/schemats.js generate -c postgresql://user:pass@host/db -o dbschema.ts

The resulting file looks like:

// Table product
export interface Product {
  id: string;
  name: string;
  description: string;
  created_at: Date;
}
export interface ProductInput {
  id?: string;
  name: string;
  description: string;
  created_at?: Date;
}
const product = {
  tableName: 'product',
  columns: ['id', 'name', 'description', 'created_at'],
  requiredForInsert: ['name', 'description'],
} as const;

export interface TableTypes {
  product: {
    select: Product;
    input: ProductInput;
  };
}

export const tables = {
  product,
};

This gives you most of the types you need for static analysis and runtime.

See SweetIQ/schemats for the original README.

About

Generate TypeScript interface definitions from SQL database schema

https://www.npmjs.com/package/schemats

License:MIT License


Languages

Language:TypeScript 97.8%Language:JavaScript 1.9%Language:TSQL 0.2%