Kononnable / typeorm-model-generator

Generates models for TypeORM from existing database.
MIT License
1.5k stars 281 forks source link

MySQL multiple database attr force option #204

Open CatsMiaow opened 4 years ago

CatsMiaow commented 4 years ago

I'm using multiple database. db1, db2, db3 ...

-d db1 does not add the database attribute.

@Entity("Table", { schema: "db1" })

https://github.com/Kononnable/typeorm-model-generator/blob/master/src/drivers/AbstractDriver.ts#L208

ent.Database = dbNames.includes(",") ? val.DB_NAME : "";

multiple databases require ,

-d db1,db2,db3 This adds the database properties but outputs all the files in one place. I want to create a folder for each database and specify the folder name when importing entities.

import { Tables } from './entity/db1/tables';

I think it would be nice to have the option of forcibly adding a database attribute even if you enter a single db(-d db1).

Kononnable commented 4 years ago

It should be easy to implemented, but I'm not sure about the design(in general). Lately we've been adding more and more options to customize generated models. The list of command parameters is getting longer and longer and I don't really like where this is going(but didn't find a better solution yet).

Kononnable commented 4 years ago

It's a bit hacky way, but actually you can achieve this right now. Just add a coma after db name -d db1,. Alternatively you can specify db which does not exits. This way library will thin that results might be from different databases and will generate database attribute.

CatsMiaow commented 4 years ago

I think it would be nice to have a configuration file like ormconfig.json or tsconfig.json if you have a lot of parameters.

typeorm-model-generator --noConfig --ce pascal -h host -p port -d database -u username -x password -e mysql -o entity ...
typeorm-model-generator -c config.path.json
Kononnable commented 4 years ago

You can run typeorm-model-generator without passing any parameters. You'll enter wizard mode which will offer to save setting to configuration file.