Go to file
Kononnable 061eca6c00 docs
2019-09-16 20:43:13 +02:00
bin readme, preparation to npm publish 2017-07-20 23:16:55 +02:00
src updated changelog, readme, fixed typos 2019-08-25 23:11:33 +02:00
test fix test compilation error 2019-08-21 23:27:26 +02:00
.editorconfig switch to eslint-typescript from deprecated tslint 2019-08-11 20:59:41 +02:00
.env.dist unfinished docs 2019-09-09 21:36:22 +02:00
.eslintignore switch to eslint-typescript from deprecated tslint 2019-08-12 17:32:28 +02:00
.eslintrc.js switch to eslint-typescript from deprecated tslint 2019-08-12 17:32:28 +02:00
.gitignore switch to eslint-typescript from deprecated tslint 2019-08-11 20:59:41 +02:00
.npmignore fix using library through npm package 2019-08-27 19:54:01 +02:00
.prettierrc added prettier 2018-02-04 23:38:43 +01:00
.travis.yml run tests with colors on CI 2019-08-17 00:42:15 +02:00
CHANGELOG.md updated changelog, readme, fixed typos 2019-08-25 23:11:33 +02:00
codecov.yml codecov config change 2019-08-09 22:55:03 +02:00
CONTRIBUTING.MD docs 2019-09-16 20:43:13 +02:00
DEVELOPER.MD docs changes 2019-09-15 23:44:55 +02:00
docker-compose.yml docker image changes 2018-12-29 17:42:53 +01:00
LICENSE Initial commit 2017-03-23 20:52:39 +01:00
package-lock.json 0.3.5 2019-08-27 20:31:16 +02:00
package.json unfinished docs 2019-09-09 21:36:22 +02:00
README.md updated changelog, readme, fixed typos 2019-08-25 23:11:33 +02:00
tsconfig.json fix typo 2019-09-09 22:16:28 +02:00
USECASES.MD docs 2019-09-16 20:43:13 +02:00

typeorm-model-generator

Build Status npm version codecov

Generates models for TypeORM from existing databases. Supported db engines:

  • Microsoft SQL Server
  • PostgreSQL
  • MySQL
  • MariaDB
  • Oracle Database
  • SQLite

Installation

Global module

To install module globally simply type npm i -g typeorm-model-generator in your console.

Npx way

Thanks to npx you can use npm modules without polluting global installs. So nothing to do here :)

To use npx you need to use npm at version at least 5.2.0. Try updating your npm by npm i -g npm

Database drivers

All database drivers except oracle are installed by default. To use typeorm-model-generator with oracle database you need to install driver with npm i oracledb and configure oracle install client on your machine.

Usage

There are two way to use this utility:

  • Use step by step wizard which will guide you though the process - just type npx typeorm-model-generator in your console.
  • Provide all parameters through command line(examples below)

Use npx typeorm-model-generator --help to see all available parameters with their descriptions. Some basic parameters below:

Usage: typeorm-model-generator -h <host> -d <database> -p [port] -u <user> -x
[password] -e [engine]

Options:
  --help                 Show help                                     [boolean]
  --version              Show version number                           [boolean]
  -h, --host             IP address/Hostname for database server
                                                          [default: "127.0.0.1"]
  -d, --database         Database name(or path for sqlite)            [required]
  -u, --user             Username for database server
  -x, --pass             Password for database server              [default: ""]
  -p, --port             Port number for database server
  -e, --engine           Database engine
          [choices: "mssql", "postgres", "mysql", "mariadb", "oracle", "sqlite"]
                                                              [default: "mssql"]
  -o, --output           Where to place generated models
                            [default: "./output"]
  -s, --schema           Schema name to create model from. Only for mssql
                         and postgres. You can pass multiple values
                         separted by comma eg. -s scheme1,scheme2,scheme3
  --ssl                                               [boolean] [default: false]

Examples

  • Creating model from local MSSQL database
    • Global module
      typeorm-model-generator -h localhost -d tempdb -u sa -x !Passw0rd -e mssql -o .
      
    • Npx Way
      npx typeorm-model-generator -h localhost -d tempdb -u sa -x !Passw0rd -e mssql -o .
      
  • Creating model from local Postgres database, public schema with ssl connection
    • Global module
      typeorm-model-generator -h localhost -d postgres -u postgres -x !Passw0rd -e postgres -o . -s public --ssl
      
    • Npx Way
      npx typeorm-model-generator -h localhost -d postgres -u postgres -x !Passw0rd -e postgres -o . -s public --ssl
      
  • Creating model from SQLite database
    • Global module
      typeorm-model-generator -d "Z:\sqlite.db" -e sqlite -o .
      
    • Npx Way
      npx typeorm-model-generator -d "Z:\sqlite.db" -e sqlite -o .
      

Naming strategy

If you want to generate custom names for properties in generated entities you need to use custom naming strategy. You need to create your own version of NamingStrategy and pass it as command parameter.

typeorm-model-generator -d typeorm_mg --namingStrategy=./NamingStrategy -e sqlite -db /tmp/sqliteto.db