You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 10, 2022. It is now read-only.
First of all, I've started using this tool recently and it's wonderful, great job.
Would be good an option to remove a table_prefix before generating entities.
I decided to delete my entities files after i changed them alot, my case looks like this:
All good with the following:
TypeORM:
entityPrefix = web_
Entities:
Account
User
Session
Tables:
web_account
web_user
web_session
As i said before, i deleted all the entities and used typeorm-model-generator to generate new ones, to my surprise the output was:
Not good, different files:
Entities:
WebAccount
WebUser
WebSession
What is should have been:
Entities:
Account
User
Session
Which turned my problem into another problem since my code was bound to the previous -unprefixed- entities, and this could be fixed with a new option to specify a table prefix and extract ONLY those tables. In the meantime i managed to fix it with a custom naming strategy, but it would be nice to label issue this as an enhancement, and the --removePrefix used should end in ormconfig.json.
Here is the code i used in the strategy:
let entityPrefix = getFromArgv('--removePrefix') || '';
function entityName(oldEntityName, entity) {
let ep = entityPrefix;
if (ep && ep.trim().length && oldEntityName.startsWith(ep)) {
entity.sqlName = entity.sqlName.substr(ep.length);
entity.columns = entity.columns.map(item => {
if (item.hasOwnProperty('default') && item.default) {
item.default = item.default.replace(/"'(.*)'"/gi, '"$1"')
}
return item;
})
return oldEntityName.substr(ep.length);
}
return oldEntityName;
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
First of all, I've started using this tool recently and it's wonderful, great job.
Would be good an option to remove a table_prefix before generating entities.
I decided to delete my entities files after i changed them alot, my case looks like this:
All good with the following:
TypeORM:
Entities:
Tables:
As i said before, i deleted all the entities and used typeorm-model-generator to generate new ones, to my surprise the output was:
Not good, different files:
Entities:
What is should have been:
Entities:
Which turned my problem into another problem since my code was bound to the previous -unprefixed- entities, and this could be fixed with a new option to specify a table prefix and extract ONLY those tables. In the meantime i managed to fix it with a custom naming strategy, but it would be nice to label issue this as an enhancement, and the
--removePrefix
used should end inormconfig.json
.Here is the code i used in the strategy:
$ typeorm-model-generator --namedStrategy=./CustomFile.js --removePrefix web_ ...connectionProps
[email protected]
node v14.17.0
The text was updated successfully, but these errors were encountered: