A simple cli to generate typescript interfaces, types or classes based on database tables. Currently only supports mysql.
Also make sure the nessacery database drivers are also installed.
npm i -g tsmg
Pass a configuration file to parse. Consult example-config.json
and parameters stated below.
tsmg -c config.json
driver
a string with the database driver to use. Currently, only supportsmysql
.driverOptions
an object with the connection parameters to be passed to the connection object.dir
a string with the default directory to place generated models, can be overridden for specific tables.defaultDb
a string with the default database to use, can be overridden for specific tables.defaultType
a string withinterface
,class
ortype
to be generated by default.defaultSuffix
a suffix to be appended to the file names.defaultConnector
a string with a connector to use between the suffix and the main name of the file.tabSize
default is 4.case
the case to use while naming models, one of:camel
,pascal
orsnake
. Default:camel
.renameClassToCase
boolean to rename tables in other naming nomenclatures into the specifiedcase
.renameAttributeToCase
boolean to rename attributes in the models into the specifiedcase
.setNullAsOptional
boolean to uses?:
for null attributes from the table in the model.dateTimeAsDate
boolean to type mysqldatettime
fields as javascriptDate
objects.dateAsDate
boolean to type mysqldate
fields as javascriptDate
objects.reWrite
boolean to truncate and use any files when generating models.modelViews
boolean to include sql views when generating models.entireDatabase
boolean to generate models for all the tables in the given database,tables
is ignored.classOptions
default options to use when generating classes.constructor
boolean to generate a default constructor for the classsqlCRUD
boolean to generate sql CRUD functions for the class (Not yet implemented).
tables
an array of objects or strings with the tables to generate models for.- accepts a string which is a table's name.
- An object:
type
override.suffix
override.name
override.database
override.constructor
override.sqlCRUD
override.omit
an array of string or regex to omit attributes from the given table matching the filters.