Compare commits

...

17 Commits
legacy ... dev

Author SHA1 Message Date
18482ebb55 add remove columns in relation option 2021-12-27 20:50:48 +01:00
9315b4a992 add skip generation of non-primary key indexes option 2021-12-27 20:50:21 +01:00
kononnable
1d3eaa0dc3 0.4.6 2021-09-07 13:30:02 +02:00
kononnable
6c0530fb21 changelog 2021-09-07 13:23:39 +02:00
kononnable
392f19cb8b reverse sleep in oracle CI tests 2021-09-07 12:57:17 +02:00
kononnable
6559f3bebb try fix oracle CI 2021-09-07 11:29:50 +02:00
kononnable
d74abacc69 update CI tested node versions 2021-09-07 11:16:02 +02:00
kononnable
baf9eff7bb autoformatting 2021-09-07 11:13:43 +02:00
kononnable
5303155f7a update dependencies 2021-09-07 11:13:12 +02:00
kononnable
787ad5fdec
Merge pull request #326 from HHongSeungWoo/master
fix: fix typecasting problem when using old version mysql
2021-05-21 10:22:32 +02:00
kononnable
b6840bd955 0.4.5 2021-03-02 22:09:42 +01:00
kononnable
e01526547e changelog 2021-03-02 22:00:28 +01:00
kononnable
4bbe80e40d fix coverage reporting 2021-02-24 20:55:46 +01:00
kononnable
ee634f1dc0 change CI to github actions
travis demand payment and stopped working due to policy changes and a bug
2021-02-24 20:40:26 +01:00
kononnable
0f19ab0e26 fix oracle driver to work with latest typeorm #328 2021-02-22 20:03:47 +01:00
kononnable
955d694785
maintenance phase 2021-02-22 01:04:50 +01:00
HHongSeungWoo
04cce00b46 fix: fix old mysql query result ony buffer 2021-02-06 15:59:08 +09:00
16 changed files with 1729 additions and 1160 deletions

70
.github/workflows/ci-tests.yml vendored Normal file
View File

@ -0,0 +1,70 @@
name: CI tests for most supported db drivers
on:
push:
branches-ignore:
- "no-engines"
tags-ignore:
- "*-no-engines"
pull_request:
env:
POSTGRES_Skip: 0
POSTGRES_Host: localhost
POSTGRES_Port: 5432
POSTGRES_Username: test
POSTGRES_Password: test
POSTGRES_Database: test
POSTGRES_SSL: 0
MYSQL_Skip: 0
MYSQL_Host: localhost
MYSQL_Port: 3306
MYSQL_Username: root
MYSQL_Password: admin
MYSQL_Database: test
MYSQL_SSL: 0
MARIADB_Skip: 0
MARIADB_Host: localhost
MARIADB_Port: 3307
MARIADB_Username: root
MARIADB_Password: admin
MARIADB_Database: test
MARIADB_SSL: 0
MSSQL_Skip: 0
MSSQL_Host: localhost
MSSQL_Port: 1433
MSSQL_Username: sa
MSSQL_Password: Admin12345
MSSQL_Database: typeorm_mg
MSSQL_SSL: 0
SQLITE_Skip: 0
SQLITE_Database: /tmp/sqlitedb.db
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
steps:
- name: Checkout the repo
uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Setup containers
run: docker-compose up -d mysql mariadb postgres mssql
- name: Install dependencies
run: npm ci
- name: Test
run: npm t
- name: Push coverage
if: github.ref == 'refs/heads/master'
uses: codecov/codecov-action@v1

69
.github/workflows/oracle.yml vendored Normal file
View File

@ -0,0 +1,69 @@
name: CI tests for oracle db driver
on:
push:
branches-ignore:
- "no-engines"
tags-ignore:
- "*-no-engines"
pull_request:
env:
ORACLE_Skip: 0
ORACLE_Host: localhost
ORACLE_Port: 1521
ORACLE_SSL: 0
ORACLE_UsernameSys: sys
ORACLE_PasswordSys: Oradoc_db1
ORACLE_Database: orclpdb1.localdomain
ORACLE_Username: typeorm_mg
ORACLE_Password: Passw0rd
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
steps:
- name: Login to registry
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_LOGIN }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Checkout the repo
uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Setup containers
run: docker-compose up -d oracle oracle_client
- name: Install dependencies
run: npm ci
- name: Setup oracle client
run: |
wget https://download.oracle.com/otn_software/linux/instantclient/195000/instantclient-basiclite-linux.x64-19.5.0.0.0dbru.zip
unzip instantclient-basiclite-linux.x64-19.5.0.0.0dbru.zip -d /tmp/oracle
wget https://download.oracle.com/otn_software/linux/instantclient/195000/instantclient-sqlplus-linux.x64-19.5.0.0.0dbru.zip
unzip instantclient-sqlplus-linux.x64-19.5.0.0.0dbru.zip -d /tmp/oracle
sudo sh -c "echo /tmp/oracle/instantclient_19_5 > /etc/ld.so.conf.d/oracle-instantclient.conf";sudo ldconfig
sh -c 'echo WHENEVER SQLERROR EXIT FAILURE > /tmp/user.sql; echo CREATE USER typeorm_mg IDENTIFIED BY Passw0rd\; >> /tmp/user.sql; echo GRANT CONNECT TO typeorm_mg\; >> /tmp/user.sql; echo GRANT UNLIMITED TABLESPACE TO typeorm_mg\; >> /tmp/user.sql; echo exit >> /tmp/user.sql'
sudo apt install libaio1
until /tmp/oracle/instantclient_19_5/sqlplus -L -S sys/Oradoc_db1@//localhost:1521/orclpdb1.localdomain as sysdba @/tmp/user.sql ; do echo waiting for oracle; sleep 10; done;
npm install oracledb --no-save
- name: Test
run: npm t
env:
LD_LIBRARY_PATH: /tmp/oracle/instantclient_19_5
- name: Push coverage
if: github.ref == 'refs/heads/master'
uses: codecov/codecov-action@v1

View File

@ -1,52 +0,0 @@
language: node_js
node_js:
- 15
- 14
- 12
- 10
cache: npm
branches:
except:
- no-engines
services:
- docker
env:
jobs:
- POSTGRES_Skip=0 POSTGRES_Host=localhost POSTGRES_Port=5432 POSTGRES_Username=test
POSTGRES_Password=test POSTGRES_Database=test POSTGRES_SSL=0 MYSQL_Skip=0
MYSQL_Host=localhost MYSQL_Port=3306 MYSQL_Username=root MYSQL_Password=admin
MYSQL_Database=test MYSQL_SSL=0 MARIADB_Skip=0 MARIADB_Host=localhost MARIADB_Port=3307
MARIADB_Username=root MARIADB_Password=admin MARIADB_Database=test MARIADB_SSL=0
MSSQL_Skip=0 MSSQL_Host=localhost MSSQL_Port=1433 MSSQL_Username=sa MSSQL_Password=Admin12345
MSSQL_Database=typeorm_mg MSSQL_SSL=0
ORACLE_Skip=0
ORACLE_Host=localhost
ORACLE_Port=1521
ORACLE_SSL=0
ORACLE_UsernameSys=sys
ORACLE_PasswordSys=Oradoc_db1
ORACLE_Database=orclpdb1.localdomain
ORACLE_Username=typeorm_mg
ORACLE_Password=Passw0rd
SQLITE_Skip=0
SQLITE_Database=/tmp/sqlitedb.db
before_install:
- sudo service mysql stop
- sudo service postgresql stop
- images=(mysql mariadb postgres mssql)
- if [ -z "$DOCKER_USERNAME" ]; then echo "DOCKER_USERNAME is unset"; else echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin; fi
- if [ -z "$DOCKER_USERNAME" ]; then export ORACLE_Skip=1; else images=(${images[@]} oracle oracle_client); fi
- if [ -n "$DOCKER_USERNAME" ]; then docker-compose up -d ${images[@]}; fi
- echo ${images[@]}
- docker-compose pull --ignore-pull-failures ${images[@]}
- docker-compose up -d ${images[@]}
before_script:
- if [ -n "$DOCKER_USERNAME" ]; then mkdir /opt/oracle; npm i oracledb --no-save; docker cp typeorm-mg-oracle-client:/usr/lib/oracle/12.2/client64/lib /opt/oracle/instantclient_12_2; fi
- export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2:$LD_LIBRARY_PATH
script:
- travis_retry sh -c 'sleep 90 && npm t -- --colors'
after_success:
- codecov
after_failure:
- docker-compose logs
- docker ps

View File

@ -1,5 +1,13 @@
# Changelog
## 0.4.6
* Fix typecasting problem when using old version mysql (#326)
* Update dependencies
## 0.4.5
* **typeorm-model-generator enters maintenance phase (#329)**
* Fix oracle driver to work with latest version of typeorm (#328)
## 0.4.4
* Add ltree type support for PostgreSQL (#318)
* Mysql fulltext index base support (#285)

View File

@ -1,9 +1,11 @@
# typeorm-model-generator
[![Build Status](https://travis-ci.org/Kononnable/typeorm-model-generator.svg?branch=master)](https://travis-ci.org/Kononnable/typeorm-model-generator)
[![npm version](https://badge.fury.io/js/typeorm-model-generator.svg)](https://badge.fury.io/js/typeorm-model-generator)
[![codecov](https://codecov.io/gh/Kononnable/typeorm-model-generator/branch/master/graph/badge.svg)](https://codecov.io/gh/Kononnable/typeorm-model-generator)
***
## :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.
Supported db engines:
* Microsoft SQL Server

2400
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "typeorm-model-generator",
"version": "0.4.4",
"version": "0.4.6",
"description": "Generates models for TypeORM from existing databases.",
"bin": "bin/typeorm-model-generator",
"main": "./dist/src/library.js",
@ -27,62 +27,62 @@
"homepage": "https://github.com/Kononnable/typeorm-model-generator#readme",
"dependencies": {
"change-case": "^4.1.2",
"fs-extra": "^9.0.1",
"handlebars": "^4.7.6",
"fs-extra": "^9.1.0",
"handlebars": "^4.7.7",
"inquirer": "^7.3.3",
"mssql": "^6.3.1",
"mysql2": "^2.2.5",
"pg": "^8.5.1",
"mssql": "^6.3.2",
"mysql2": "^2.3.0",
"pg": "^8.7.1",
"pluralize": "^8.0.0",
"prettier": "^2.2.1",
"prettier": "^2.3.2",
"reflect-metadata": "^0.1.13",
"sqlite3": "^5.0.0",
"typeorm": "^0.2.29",
"sqlite3": "^5.0.2",
"typeorm": "^0.2.37",
"yargs": "^16.2.0"
},
"devDependencies": {
"@types/array.prototype.flatmap": "^1.2.2",
"@types/chai": "^4.2.14",
"@types/chai-as-promised": "^7.1.3",
"@types/chai": "^4.2.21",
"@types/chai-as-promised": "^7.1.4",
"@types/chai-subset": "^1.3.3",
"@types/eslint": "^7.2.6",
"@types/fs-extra": "^9.0.6",
"@types/eslint": "^7.28.0",
"@types/fs-extra": "^9.0.12",
"@types/handlebars": "^4.1.0",
"@types/inquirer": "^7.3.1",
"@types/mocha": "^8.2.0",
"@types/mssql": "^6.0.7",
"@types/mysql": "^2.15.17",
"@types/node": "^14.14.20",
"@types/oracledb": "^5.1.0",
"@types/pg": "^7.14.7",
"@types/inquirer": "^7.3.3",
"@types/mocha": "^8.2.3",
"@types/mssql": "^6.0.8",
"@types/mysql": "^2.15.19",
"@types/node": "^14.17.15",
"@types/oracledb": "^5.2.1",
"@types/pg": "^7.14.11",
"@types/pluralize": "0.0.29",
"@types/prettier": "^2.1.6",
"@types/sinon": "^9.0.10",
"@types/sqlite3": "^3.1.6",
"@types/yargs": "^15.0.12",
"@types/prettier": "^2.3.2",
"@types/sinon": "^9.0.11",
"@types/sqlite3": "^3.1.7",
"@types/yargs": "^15.0.14",
"@typescript-eslint/eslint-plugin": "^3.7.1",
"@typescript-eslint/parser": "^3.7.1",
"@typescript-eslint/typescript-estree": "^3.7.1",
"array.prototype.flatmap": "^1.2.4",
"chai": "^4.2.0",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"chai-subset": "^1.6.0",
"codecov": "^3.8.1",
"dotenv": "^8.2.0",
"eslint": "^7.17.0",
"codecov": "^3.8.3",
"dotenv": "^8.6.0",
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-import": "^2.22.1",
"husky": "^4.3.7",
"lint-staged": "^10.5.3",
"mocha": "^8.2.1",
"eslint-plugin-import": "^2.24.2",
"husky": "^4.3.8",
"lint-staged": "^10.5.4",
"mocha": "^8.4.0",
"ncp": "^2.0.0",
"nyc": "^15.1.0",
"rimraf": "^3.0.2",
"sinon": "^9.2.3",
"sinon-chai": "^3.5.0",
"sinon": "^9.2.4",
"sinon-chai": "^3.7.0",
"ts-node": "^9.1.1",
"typescript": "^4.1.3",
"typescript": "^4.4.2",
"yn": "^4.0.0"
},
"husky": {
@ -91,7 +91,7 @@
}
},
"nyc": {
"check-coverage": true,
"check-coverage": false,
"all": true,
"extension": [
".ts",

View File

@ -23,6 +23,8 @@ export default interface IGenerationOptions {
skipSchema: boolean;
indexFile: boolean;
exportType: "named" | "default";
skipNonPrimaryKeyIndexes: boolean;
removeColumnsInRelation: boolean;
}
export const eolConverter = {
@ -49,6 +51,8 @@ export function getDefaultGenerationOptions(): IGenerationOptions {
skipSchema: false,
indexFile: false,
exportType: "named",
skipNonPrimaryKeyIndexes: false,
removeColumnsInRelation: true,
};
return generationOptions;
}

View File

@ -89,7 +89,11 @@ export default function modelCustomizationPhase(
}
namingStrategy.enablePluralization(generationOptions.pluralizeNames);
let retVal = removeIndicesGeneratedByTypeorm(dbModel);
retVal = removeColumnsInRelation(dbModel);
if (generationOptions.removeColumnsInRelation) {
retVal = removeColumnsInRelation(dbModel);
}
retVal = applyNamingStrategy(namingStrategy, dbModel);
retVal = addImportsAndGenerationOptions(retVal, generationOptions);
retVal = removeColumnDefaultProperties(retVal, defaultValues);

View File

@ -136,15 +136,16 @@ export default abstract class AbstractDriver {
};
}
),
inverseJoinColumns: junctionEntity.relations[1].joinColumnOptions!.map(
(v, i) => {
return {
referencedColumnName: v.referencedColumnName,
name: junctionEntity.relations[1]
.joinColumnOptions![i].name,
};
}
),
inverseJoinColumns:
junctionEntity.relations[1].joinColumnOptions!.map(
(v, i) => {
return {
referencedColumnName: v.referencedColumnName,
name: junctionEntity.relations[1]
.joinColumnOptions![i].name,
};
}
),
};
if (junctionEntity.database) {
firstRelation.joinTableOptions.database =
@ -183,7 +184,8 @@ export default abstract class AbstractDriver {
await this.GetIndexesFromEntity(
dbModel,
connectionOptions.schemaNames,
connectionOptions.databaseNames
connectionOptions.databaseNames,
generationOptions,
);
AbstractDriver.FindPrimaryColumnsFromIndexes(dbModel);
dbModel = await this.GetRelations(
@ -384,7 +386,8 @@ export default abstract class AbstractDriver {
public abstract GetIndexesFromEntity(
entities: Entity[],
schemas: string[],
dbNames: string[]
dbNames: string[],
generationOptions: IGenerationOptions
): Promise<Entity[]>;
public abstract GetRelations(

View File

@ -272,7 +272,8 @@ export default class MssqlDriver extends AbstractDriver {
public async GetIndexesFromEntity(
entities: Entity[],
schemas: string[],
dbNames: string[]
dbNames: string[],
generationOptions: IGenerationOptions,
): Promise<Entity[]> {
const request = new this.MSSQL.Request(this.Connection);
/* eslint-disable camelcase */
@ -340,7 +341,9 @@ export default class MssqlDriver extends AbstractDriver {
records.forEach((record) => {
indexInfo.columns.push(record.ColumnName);
});
ent.indices.push(indexInfo);
if (!generationOptions.skipNonPrimaryKeyIndexes || indexInfo.primary) {
ent.indices.push(indexInfo);
}
});
});

View File

@ -319,7 +319,8 @@ export default class MysqlDriver extends AbstractDriver {
public async GetIndexesFromEntity(
entities: Entity[],
schemas: string[],
dbNames: string[]
dbNames: string[],
generationOptions: IGenerationOptions,
): Promise<Entity[]> {
/* eslint-disable camelcase */
const response = await this.ExecQuery<{
@ -359,7 +360,9 @@ export default class MysqlDriver extends AbstractDriver {
records.forEach((record) => {
indexInfo.columns.push(record.ColumnName);
});
ent.indices.push(indexInfo);
if (!generationOptions.skipNonPrimaryKeyIndexes || indexInfo.primary) {
ent.indices.push(indexInfo);
}
});
});
@ -493,6 +496,17 @@ export default class MysqlDriver extends AbstractDriver {
};
}
config.typeCast = (field, next) => {
switch (field.type) {
case "VAR_STRING":
return field.string();
case "BLOB":
return field.string();
default:
return next();
}
};
const promise = new Promise<boolean>((resolve, reject) => {
this.Connection = this.MYSQL.createConnection(config);
@ -536,7 +550,7 @@ export default class MysqlDriver extends AbstractDriver {
const stream = query.stream({});
const promise = new Promise<boolean>((resolve, reject) => {
stream.on("data", (chunk) => {
ret.push((chunk as unknown) as T);
ret.push(chunk as unknown as T);
});
stream.on("error", (err) => reject(err));
stream.on("end", () => resolve(true));

View File

@ -13,7 +13,7 @@ import { RelationInternal } from "../models/RelationInternal";
export default class OracleDriver extends AbstractDriver {
public defaultValues: DataTypeDefaults = new TypeormDriver.OracleDriver({
options: undefined,
options: {},
} as any).dataTypeDefaults;
public readonly standardPort = 1521;
@ -236,7 +236,12 @@ export default class OracleDriver extends AbstractDriver {
return entities;
}
public async GetIndexesFromEntity(entities: Entity[]): Promise<Entity[]> {
public async GetIndexesFromEntity(
entities: Entity[],
schemas: string[],
dbNames: string[],
generationOptions: IGenerationOptions,
): Promise<Entity[]> {
const response = (
await this.Connection.execute<{
COLUMN_NAME: string;
@ -271,7 +276,9 @@ export default class OracleDriver extends AbstractDriver {
records.forEach((record) => {
indexInfo.columns.push(record.COLUMN_NAME);
});
ent.indices.push(indexInfo);
if (!generationOptions.skipNonPrimaryKeyIndexes || indexInfo.primary) {
ent.indices.push(indexInfo);
}
});
});

View File

@ -433,9 +433,9 @@ export default class PostgresDriver extends AbstractDriver {
break;
default:
if (enumValues) {
ret.tsType = (`"${enumValues
ret.tsType = `"${enumValues
.split(",")
.join('" | "')}"` as never) as string;
.join('" | "')}"` as never as string;
ret.sqlType = "enum";
ret.enumValues = enumValues.split(",");
}
@ -451,7 +451,9 @@ export default class PostgresDriver extends AbstractDriver {
public async GetIndexesFromEntity(
entities: Entity[],
schemas: string[]
schemas: string[],
dbNames: string[],
generationOptions: IGenerationOptions,
): Promise<Entity[]> {
const response: {
tablename: string;
@ -506,7 +508,9 @@ export default class PostgresDriver extends AbstractDriver {
records.forEach((record) => {
indexInfo.columns.push(record.columnname);
});
ent.indices.push(indexInfo);
if (!generationOptions.skipNonPrimaryKeyIndexes || indexInfo.primary) {
ent.indices.push(indexInfo);
}
});
});

View File

@ -91,9 +91,10 @@ export default class SqliteDriver extends AbstractDriver {
const options: Column["options"] = { name: resp.name };
if (resp.notnull === 0) options.nullable = true;
const isPrimary = resp.pk > 0 ? true : undefined;
const defaultValue = SqliteDriver.ReturnDefaultValueFunction(
resp.dflt_value
);
const defaultValue =
SqliteDriver.ReturnDefaultValueFunction(
resp.dflt_value
);
const columnType = resp.type
.replace(/\([0-9 ,]+\)/g, "")
.toLowerCase()
@ -257,7 +258,12 @@ export default class SqliteDriver extends AbstractDriver {
return entities;
}
public async GetIndexesFromEntity(entities: Entity[]): Promise<Entity[]> {
public async GetIndexesFromEntity(
entities: Entity[],
schemas: string[],
dbNames: string[],
generationOptions: IGenerationOptions,
): Promise<Entity[]> {
await Promise.all(
entities.map(async (ent) => {
const response = await this.ExecQuery<{
@ -298,7 +304,9 @@ export default class SqliteDriver extends AbstractDriver {
v.options.unique = true;
});
}
ent.indices.push(indexInfo);
if (!generationOptions.skipNonPrimaryKeyIndexes || indexInfo.primary) {
ent.indices.push(indexInfo);
}
})
);
})
@ -337,7 +345,8 @@ export default class SqliteDriver extends AbstractDriver {
match: string;
}>(`PRAGMA foreign_key_list('${entity.tscName}');`);
const relationsTemp: RelationInternal[] = [] as RelationInternal[];
const relationsTemp: RelationInternal[] =
[] as RelationInternal[];
const relationKeys = new Set(response.map((v) => v.id));
relationKeys.forEach((relationId) => {

View File

@ -65,9 +65,10 @@ function makeDefaultConfigs() {
connectionOptions,
};
}
function readTOMLConfig(
options: options
): { options; fullConfigFile: boolean } {
function readTOMLConfig(options: options): {
options;
fullConfigFile: boolean;
} {
if (!fs.existsSync(path.resolve(process.cwd(), ".tomg-config"))) {
return { options, fullConfigFile: false };
}
@ -276,6 +277,16 @@ function checkYargsParameters(options: options): options {
describe:
"Skip schema generation for specific tables. You can pass multiple values separated by comma",
},
skipNonPrimaryKeyIndexes: {
boolean: true,
default: options.generationOptions.skipNonPrimaryKeyIndexes,
describe: "Skip generation of non-primary key indexes",
},
removeColumnsInRelation: {
boolean: true,
default: options.generationOptions.removeColumnsInRelation,
describe: "Remove columns in relation",
},
tables: {
string: true,
default: options.connectionOptions.onlyTables.join(","),
@ -296,7 +307,7 @@ function checkYargsParameters(options: options): options {
boolean: true,
default: options.generationOptions.exportType === "default",
describe: "Generate index file",
},
}
});
options.connectionOptions.databaseNames = argv.d.split(",");
@ -326,19 +337,27 @@ function checkYargsParameters(options: options): options {
options.connectionOptions.onlyTables = tables;
options.generationOptions.activeRecord = argv.a;
options.generationOptions.generateConstructor = argv.generateConstructor;
options.generationOptions.convertCaseEntity = argv.ce as IGenerationOptions["convertCaseEntity"];
options.generationOptions.convertCaseFile = argv.cf as IGenerationOptions["convertCaseFile"];
options.generationOptions.convertCaseProperty = argv.cp as IGenerationOptions["convertCaseProperty"];
options.generationOptions.convertEol = argv.eol as IGenerationOptions["convertEol"];
options.generationOptions.convertCaseEntity =
argv.ce as IGenerationOptions["convertCaseEntity"];
options.generationOptions.convertCaseFile =
argv.cf as IGenerationOptions["convertCaseFile"];
options.generationOptions.convertCaseProperty =
argv.cp as IGenerationOptions["convertCaseProperty"];
options.generationOptions.convertEol =
argv.eol as IGenerationOptions["convertEol"];
options.generationOptions.lazy = argv.lazy;
options.generationOptions.customNamingStrategyPath = argv.namingStrategy;
options.generationOptions.noConfigs = argv.noConfig;
options.generationOptions.propertyVisibility = argv.pv as IGenerationOptions["propertyVisibility"];
options.generationOptions.propertyVisibility =
argv.pv as IGenerationOptions["propertyVisibility"];
options.generationOptions.relationIds = argv.relationIds;
options.generationOptions.skipSchema = argv.skipSchema;
options.generationOptions.skipNonPrimaryKeyIndexes = argv.skipNonPrimaryKeyIndexes;
options.generationOptions.removeColumnsInRelation = argv.removeColumnsInRelation;
options.generationOptions.resultsPath = argv.o;
options.generationOptions.pluralizeNames = !argv.disablePluralization;
options.generationOptions.strictMode = argv.strictMode as IGenerationOptions["strictMode"];
options.generationOptions.strictMode =
argv.strictMode as IGenerationOptions["strictMode"];
options.generationOptions.indexFile = argv.index;
options.generationOptions.exportType = argv.defaultExport
? "default"
@ -437,9 +456,8 @@ async function useInquirer(options: options): Promise<options> {
options.connectionOptions.schemaNames = (
await inquirer.prompt([
{
default: options.connectionOptions.schemaNames.join(
","
),
default:
options.connectionOptions.schemaNames.join(","),
message:
"Database schema: (You can pass multiple values separated by comma)",
name: "schema",
@ -548,16 +566,16 @@ async function useInquirer(options: options): Promise<options> {
checked: options.generationOptions.lazy,
},
{
name:
"Use ActiveRecord syntax for generated models",
name: "Use ActiveRecord syntax for generated models",
value: "activeRecord",
checked: options.generationOptions.activeRecord,
},
{
name: "Use custom naming strategy",
value: "namingStrategy",
checked: !!options.generationOptions
.customNamingStrategyPath,
checked:
!!options.generationOptions
.customNamingStrategyPath,
},
{
name: "Generate RelationId fields",
@ -565,14 +583,12 @@ async function useInquirer(options: options): Promise<options> {
checked: options.generationOptions.relationIds,
},
{
name:
"Omits schema identifier in generated entities",
name: "Omits schema identifier in generated entities",
value: "skipSchema",
checked: options.generationOptions.skipSchema,
},
{
name:
"Generate constructor allowing partial initialization",
name: "Generate constructor allowing partial initialization",
value: "constructor",
checked:
options.generationOptions.generateConstructor,
@ -595,8 +611,7 @@ async function useInquirer(options: options): Promise<options> {
checked: false,
},
{
name:
"Pluralize OneToMany, ManyToMany relation names",
name: "Pluralize OneToMany, ManyToMany relation names",
value: "pluralize",
checked: options.generationOptions.pluralizeNames,
},
@ -612,6 +627,16 @@ async function useInquirer(options: options): Promise<options> {
options.generationOptions.exportType ===
"default",
},
{
name: "Skip generation of non-primary key indexes",
value: "skipNonPrimaryKeyIndexes",
checked: options.generationOptions.skipNonPrimaryKeyIndexes,
},
{
name: "Remove columns in relation",
value: "removeColumnsInRelation",
checked: options.generationOptions.removeColumnsInRelation,
}
],
message: "Available customizations",
name: "selected",
@ -645,31 +670,27 @@ async function useInquirer(options: options): Promise<options> {
])
).strictMode;
options.generationOptions.noConfigs = !customizations.includes(
"config"
);
options.generationOptions.pluralizeNames = customizations.includes(
"pluralize"
);
options.generationOptions.noConfigs =
!customizations.includes("config");
options.generationOptions.pluralizeNames =
customizations.includes("pluralize");
options.generationOptions.lazy = customizations.includes("lazy");
options.generationOptions.activeRecord = customizations.includes(
"activeRecord"
);
options.generationOptions.relationIds = customizations.includes(
"relationId"
);
options.generationOptions.skipSchema = customizations.includes(
"skipSchema"
);
options.generationOptions.generateConstructor = customizations.includes(
"constructor"
);
options.generationOptions.activeRecord =
customizations.includes("activeRecord");
options.generationOptions.relationIds =
customizations.includes("relationId");
options.generationOptions.skipSchema =
customizations.includes("skipSchema");
options.generationOptions.generateConstructor =
customizations.includes("constructor");
options.generationOptions.indexFile = customizations.includes("index");
options.generationOptions.exportType = customizations.includes(
"defaultExport"
)
? "default"
: "named";
options.generationOptions.skipNonPrimaryKeyIndexes = customizations.includes("skipNonPrimaryKeyIndexes");
options.generationOptions.removeColumnsInRelation = customizations.includes("removeColumnsInRelation");
if (customizations.includes("namingStrategy")) {
const namingStrategyPath = (
@ -692,7 +713,8 @@ async function useInquirer(options: options): Promise<options> {
).namingStrategy;
if (namingStrategyPath && namingStrategyPath !== "") {
options.generationOptions.customNamingStrategyPath = namingStrategyPath;
options.generationOptions.customNamingStrategyPath =
namingStrategyPath;
} else {
options.generationOptions.customNamingStrategyPath = "";
}