typescript-enum-generator
v1.0.9
Published
Generate TypeScript enums from mssql db tables
Readme
typescript-enum-generator
Generate TypeScript Enums from MSSQL Tables
Given a SQL table with a Name, Category, and Value:
|Id|AttributeName|CategoryName| |--|-------------|------------| |1|Active|AccountStatus| |2|InActive|AccountStatus| |3|U.S. Citizen|CitizenshipStatus| |4|Non U.S. Citizen|CitizenshipStatus|
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-generatorConfiguration
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-enumA file will be generated at the given path per enumConfig
Thanks!
