1.0.9 • Published 4 years ago

typescript-enum-generator v1.0.9

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

typescript-enum-generator

Generate TypeScript Enums from MSSQL Tables

Given a SQL table with a Name, Category, and Value:

IdAttributeNameCategoryName
1ActiveAccountStatus
2InActiveAccountStatus
3U.S. CitizenCitizenshipStatus
4Non U.S. CitizenCitizenshipStatus

This project can generate TypeScript enums that look like this:

export enum AccountStatus {
  Active = 1,
  InActive = 2
}

export enum CitizenshipStatus {
  USCitizen = 3,
  NonUSCitizen = 4
}

This has been useful for querying and filtering results from a GraphQL API


Getting Started

Installation

npm install typescript-enum-generator

Configuration

Add a ts-enum-config.json file to the root of your project

{
  "connectionString": "mssql://<user>:<password>@<server>/<database>",
  "enumConfig": [
    {
      "table": "Attribute",
      "enumCategoryColumn": "CategoryName",
      "enumNameColumn": "AttributeName",
      "enumValueColumn": "Id",
      "outputFile": "<path relative to project root>/AttributeEnum.ts"
    }
  ]
}

Add ?encrypt=true to the end of the connection string if using Azure SQL

Generate Code

ts-enum

A file will be generated at the given path per enumConfig

Thanks!

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago