Giter VIP home page Giter VIP logo

sql-ts's Introduction

sql-ts

npm (scoped) npm Run Tests

Generate TypeScript types for tables and views in a SQL database.

Includes comments from tables, views and columns for supported providers.

Highly configurable: choose your own naming and casing schemes, add types, extend base types, and more.

Supports the following database providers: MySQL, Microsoft SQL Server, SQLite and Postgres.

CREATE TABLE [dbo].[Employees](
	[EmployeeID] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](20) NOT NULL,
	[BirthDate] [datetime] NULL,
	[Photo] [image] NULL
)
export interface EmployeesEntity {
  'EmployeeID'?: number;
  'Name': string;
  'BirthDate'?: Date | null;
  'Photo'?: Buffer | null;
}

Documentation

Full documentation with all configuration options and node APIs are available at https://rmp135.github.io/sql-ts/.

Installation

Install into your project using npm / yarn.

npm install @rmp135/sql-ts

Install your relevant SQL driver. Refer to the knex documentation to determine which driver you should install. For example npm install mysql2.

Create a configuration file, for example mysql.json. This will mirror connection details from knex. The client property will determine the SQL provider.

The most basic MySQL setup is below, modify as appropriate. Additional options can be applied by referring to the Config.

{
  "client": "mysql2",
  "connection": {
    "host": "localhost",
    "user": "user",
    "password": "password",
    "database" : "my_database"
  }
}

Usage

CLI

Run npx @rmp135/sql-ts with the path of the configuration file created above.

npx @rmp135/sql-ts -c ./mysql.json

The file will be exported with the filename Database.ts (or with the name specified via the filename config option) at the current working directory.

Node Module

For finer grained control of the exported types, you can use the node API. See how in the documentation.

sql-ts's People

Contributors

rmp135 avatar wbhumphrey avatar laurent22 avatar ajeffrey avatar jhiesey avatar dryhumor avatar javiertury avatar saostad avatar jwmonroe-outschool avatar igornadj avatar vantanev avatar jacobjmarks avatar jokecamp avatar michael-land avatar herrecito avatar wunderkind2k1 avatar tslater avatar hwhang0917 avatar hhanesand avatar ryleu avatar edorivai avatar dsempel avatar darkroku12 avatar rattrayalex avatar aitthi avatar aaroncalderon avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.