typeorm-model-generator/README.md

95 lines
4.7 KiB
Markdown
Raw Normal View History

2017-03-23 19:52:39 +00:00
# typeorm-model-generator
2017-12-27 21:48:03 +00:00
2017-05-03 19:28:58 +00:00
[![npm version](https://badge.fury.io/js/typeorm-model-generator.svg)](https://badge.fury.io/js/typeorm-model-generator)
2017-05-03 20:05:49 +00:00
[![codecov](https://codecov.io/gh/Kononnable/typeorm-model-generator/branch/master/graph/badge.svg)](https://codecov.io/gh/Kononnable/typeorm-model-generator)
2017-05-03 19:28:58 +00:00
2021-02-22 00:04:50 +00:00
***
## :warning: This project is in a maintenance phase. See [#329](https://github.com/Kononnable/typeorm-model-generator/issues/329) for details.
***
Generates models for TypeORM from existing databases.
2019-08-15 06:57:39 +00:00
Supported db engines:
2017-07-20 21:16:55 +00:00
* Microsoft SQL Server
* PostgreSQL
2017-08-14 18:28:03 +00:00
* MySQL
* MariaDB
2018-04-18 20:15:07 +00:00
* Oracle Database
2018-05-03 19:52:57 +00:00
* SQLite
2017-07-20 21:16:55 +00:00
## Installation
2020-03-12 17:48:26 +00:00
### Versions
Typeorm-model-generator comes with preinstalled driver for each supported db(except for oracle). However if you want to use it as a dev-dependency you may want to install your db driver manually to reduce dependency footprint, reduce time spent in the CI. In such case you can use version without preinstalled db drivers - `npm i typeorm-model-generator@no-engines`.
2017-07-20 21:16:55 +00:00
### 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`
2018-06-17 19:30:54 +00:00
### Database drivers
2019-08-15 06:57:39 +00:00
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](http://www.oracle.com/technetwork/database/database-technologies/instant-client/overview/index.html) on your machine.
2018-06-17 19:30:54 +00:00
2019-08-25 21:11:33 +00:00
## 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)
2017-07-20 21:16:55 +00:00
2019-08-25 21:11:33 +00:00
Use `npx typeorm-model-generator --help` to see all available parameters with their descriptions. Some basic parameters below:
2017-07-20 21:16:55 +00:00
```shell
Usage: typeorm-model-generator -h <host> -d <database> -p [port] -u <user> -x
[password] -e [engine]
Options:
2018-05-03 19:52:57 +00:00
--help Show help [boolean]
--version Show version number [boolean]
2019-08-15 06:56:08 +00:00
-h, --host IP address/Hostname for database server
2018-05-05 20:09:03 +00:00
[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
2018-05-03 19:52:57 +00:00
[choices: "mssql", "postgres", "mysql", "mariadb", "oracle", "sqlite"]
[default: "mssql"]
2018-05-05 20:09:03 +00:00
-o, --output Where to place generated models
2019-08-25 21:11:33 +00:00
[default: "./output"]
2019-08-08 19:57:29 +00:00
-s, --schema Schema name to create model from. Only for mssql
and postgres. You can pass multiple values
2019-11-10 20:26:47 +00:00
separated by comma eg. -s scheme1,scheme2,scheme3
2018-05-03 19:52:57 +00:00
--ssl [boolean] [default: false]
2017-07-20 21:16:55 +00:00
```
### Examples
* Creating model from local MSSQL database
* Global module
2017-07-20 21:16:55 +00:00
```
typeorm-model-generator -h localhost -d tempdb -u sa -x !Passw0rd -e mssql -o .
2017-07-20 21:16:55 +00:00
````
* Npx Way
2017-07-20 21:16:55 +00:00
```
npx typeorm-model-generator -h localhost -d tempdb -u sa -x !Passw0rd -e mssql -o .
2017-07-20 21:16:55 +00:00
````
2017-10-15 17:16:53 +00:00
* Creating model from local Postgres database, public schema with ssl connection
* Global module
2017-07-20 21:16:55 +00:00
```
typeorm-model-generator -h localhost -d postgres -u postgres -x !Passw0rd -e postgres -o . -s public --ssl
2017-07-20 21:16:55 +00:00
````
* Npx Way
2017-07-20 21:16:55 +00:00
```
npx typeorm-model-generator -h localhost -d postgres -u postgres -x !Passw0rd -e postgres -o . -s public --ssl
````
2018-05-05 20:09:03 +00:00
* 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 .
````
2019-09-17 18:54:28 +00:00
## Use Cases
Please take a look at [few workflows](USECASES.md) which might help you with deciding how you're gonna use typeorm-model-generator.
2018-06-17 19:30:54 +00:00
## Naming strategy
2018-06-17 19:32:50 +00:00
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](https://github.com/Kononnable/typeorm-model-generator/blob/master/src/NamingStrategy.ts) and pass it as command parameter.
2018-06-17 19:30:54 +00:00
```typeorm-model-generator -d typeorm_mg --namingStrategy=./NamingStrategy -e sqlite -db /tmp/sqliteto.db```