Skip to content
/ tsmg Public

A simple cli to generate typescript interfaces, types or classes based on database tables

License

Notifications You must be signed in to change notification settings

t348575/tsmg

Repository files navigation

tsmg (Typescript model generator) Visits

A simple cli to generate typescript interfaces, types or classes based on database tables. Currently only supports mysql.

Install

Also make sure the nessacery database drivers are also installed.

npm i -g tsmg

Usage

Pass a configuration file to parse. Consult example-config.json and parameters stated below.

tsmg -c config.json

Config parameters

  • driver a string with the database driver to use. Currently, only supports mysql.
  • 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 with interface, class or type 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 or snake. Default: camel.
  • renameClassToCase boolean to rename tables in other naming nomenclatures into the specified case.
  • renameAttributeToCase boolean to rename attributes in the models into the specified case.
  • setNullAsOptionalboolean to uses ?: for null attributes from the table in the model.
  • dateTimeAsDate boolean to type mysql datettime fields as javascript Date objects.
  • dateAsDate boolean to type mysql date fields as javascript Date 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 class
    • sqlCRUD 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.

About

A simple cli to generate typescript interfaces, types or classes based on database tables

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published