Date: July 16, 2020, 5:58 pm
Author: Akram Hossain
Typeorm is an ORM Which run in NodeJS, PhoneGap, Cordova, Ionic, Browser, NativeScript, Expo, React Native and Electron platforms.
We can use TypeORM with TypeScript and JavaScript (ES5, ES6, ES7, ES8).
TypeORM is highly influenced by other ORMs such as Entity Framework, Hibernate, Doctrine.
To generate model using TypeORM from existing database we need to install typeorm-model-generator. To install this module globally simply type
npm i -g typeorm-model-generator in your terminal.
typeorm-model-generator has following options
- --help Show help [boolean]
- --version Show version number [boolean]
- -h or --host IP address/Hostname for database server [default: "127.0.0.1"]
- -d or --database Database name(or path for sqlite) [required]
- -u or --user Username for database server
- -x or --pass Password for database server [default: ""]
- -p or --port Port number for database server
- -e or --engine Database engine [choices: "mssql", "postgres", "mysql", "mariadb", "oracle", "sqlite"] [default: "mssql"]
- -o or --output Where to place generated models [default: "./output"]
- -s or --schema Schema name to create model from. Only for mssql and postgres. You can pass multiple values separated by comma eg. -s scheme1,scheme2,scheme3
- --ssl [boolean] [default: false]
- --noConfig Doesn't create tsconfig.json and ormconfig.json [boolean] [default: false]
- --cf or --case-file Convert file names to specified case [choices: "pascal", "param", "camel", "none"] [default: "none"]
- --ce or --case-entity Convert class names to specified case [choices: "pascal", "camel", "none"] [default: "none"]
- --cp or --case-property Convert property names to specified case [choices: "pascal", "camel", "none"] [default: "none"]
- --lazy Generate lazy relations [boolean] [default: false]
- --namingStrategy Use custom naming strategy
- --relationIds Generate RelationId fields [boolean] [default: false]
- --generateConstructor Generate constructor allowing partial initialization [boolean] [default: false]
Examples:
To generate model from existing database run the below code into the terminal
npx typeorm-model-generator -h localhost -u root -x 123123 -d dbName -e mysql
Views : 5882