feat(postgres): minify aliases option#11095
Conversation
Codecov Report
@@ Coverage Diff @@
## master #11095 +/- ##
==========================================
+ Coverage 96.25% 96.29% +0.03%
==========================================
Files 94 94
Lines 9106 9143 +37
==========================================
+ Hits 8765 8804 +39
+ Misses 341 339 -2
Continue to review full report at Codecov.
|
|
@mrrinot I've found an issue related to running raw queries ... I get the following error: |
eseliger
left a comment
There was a problem hiding this comment.
Can you add a test case which would not have worked before?
|
@eseliger I'm currently looking through the tests to find where to add my tests. I put them in a new file |
|
@eseliger Tests have been added |
|
@mrrinot I checked it and generally looks very good, but when I use |
|
@mtryba I'm sorry I didn't understand your message. Do you mean it doesn't work with |
|
@mrrinot It means that when I have relations one to one everything is ok, aliases work correct but I have one relation many to many and aliases in the relation are without changes. It looks like the second line is the without alias |
|
Ho I see, I'll look into that and add a test case. |
|
At first I thought that table name aliasing wasn't affected by the Postgres limit of 64 but it seems otherwise. I need to fix that too and it complexify the problem quite a bit. Although I don't know if this fix is worth it because you would need a single alias to be > 64 character to break. The problem usually arise when chaining includes and each table's name is shorter than 64 characters. I specifically encountered the problem in my test case because I used these aliases: const alias = 'AnActualVeryLongAliasThatShouldBreakthePostgresLimitOfSixtyFourCharacters';
const longerAlias = 'AnActualVeryLongAliasThatShouldBreakthePostgresLimitOfSixtyFourCharactersButThisTimeForBelongsToMany';I'll push the fix for the belongsToMany columns not being aliased. As for the table alias problem, I think it could be done in a separate PR, I don't really know. |
|
@mrrinot I checked it and I think everything is ok ❤️ Probably you safe my life 😄 |
|
@eseliger Can we merge it? |
|
I've been testing this with a large codebase (hundreds of different queries and many deeply nested) without problems. How do we get this reviewed and merged to master? @sushantdhiman @mickhansen @papb |
eseliger
left a comment
There was a problem hiding this comment.
looking good, can you add the option minifyAliases to the type definitions? 🙂
|
Ok, so now all integration tests are good, there is a lot of unit tests failing. |
|
@mrrinot Just integration tests should be enough, once build is green I'll review this once again. |
|
@sushantdhiman I suppose I need to modify the travis.yml file but I don't know what to change. |
Co-Authored-By: Sushant <sushantdhiman@outlook.com>
|
Tests appear OK @sushantdhiman, I don't understand the codecov report failing though. |
|
Any idea how much work is left before we get this feature? |
|
Coverage is down a bit but can ignore that |
|
🎉 This PR is included in version 5.18.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
|
Can the minifyAliases option be passed to individual queries? eg. |
Tested this and confirmed you cannot pass minifyAliases: false in for individual queries. |
|
No you cannot, I thought it would be more of a global options than a individual one. |
|
If I pass |
|
I'm running into this issue but for the table names, rather than table + column names. Meaning that the names of the joined tables are already too long for Postgres, so I get an error saying the table name is specified more than once. Can we add handling for table names in addition to column names? |
|
Hi @henrywoody, please open a new issue about this so we can track progress properly, thanks |
|
Bug opened for minifyAliases not applying to the FROM clause aliases: #11937 |
Pull Request check-list
Please make sure to review and check all of these items:
npm run testornpm run test-DIALECTpass with this change (including linting)?Description of change
Add alias minifier to fix the following issue: #2084
All aliases are replaced with an auto increment alias (_1, _2, _3 ...) before querying and immediately replaced after the query has been run.
This does pose a colliding problem if any column is named accordingly to the alias and I could see the case for making it customizable or just more complex.
I didn't found the right place in the doc to warn users about that but I would be happy to write it down somewhere appropriate.
(Also thanks to @mattp94 for helping me do this)