refactor: move all dialect conditional logic into subclass#12217
refactor: move all dialect conditional logic into subclass#12217sushantdhiman merged 2 commits intomasterfrom
Conversation
3052864 to
3734525
Compare
|
Mostly looking for feedback on the 'breaking' changes here, the build should be fixed by tomorrow. |
|
Breaking changes you have listed are fine for me |
3734525 to
dfb0d32
Compare
Codecov Report
@@ Coverage Diff @@
## master #12217 +/- ##
==========================================
+ Coverage 95.85% 96.33% +0.48%
==========================================
Files 92 95 +3
Lines 8949 9112 +163
==========================================
+ Hits 8578 8778 +200
+ Misses 371 334 -37
Continue to review full report at Codecov.
|
|
That was.. easier to fix than I thought. |
|
OH, there are some unrelated changes in |
| @private | ||
| * Returns an object that treats MSSQL's inabilities to do certain queries. | ||
| * | ||
| * @private |
There was a problem hiding this comment.
As previously noted in other comment, remove @private directive. Comment can be improved to indicate this is a MSSQL Query Interface
| @param {object} options | ||
|
|
||
| @private | ||
| * Returns an object that treats MySQL's inabilities to do certain queries. |
There was a problem hiding this comment.
Update documentation here, say this is the MySQL query interface. This comment will be exposed in documentation
BREAKING CHANGE: All instances of `QueryInterface` and `QueryGenerator` have been renamed to their lowerCamelCase variants eg. `queryInterface` and `queryGenerator` when used as property names on Model and Dialect, the class names remain the same. `Utils.stack` has been removed. `QueryInterface` is now an abstract class. `query-interface.js` was moved to `lib/dialects/abstract/query-interface` and the exports have been reduced to `QueryInterface`, `default` and `module.exports` no longer refer to this class. `QueryInterface.addConstraint`s now only takes 2 parameters, `tableName` and `options`, previously the second parameter _could_ be a list of column names to apply the constraint to, this list must now be passed in `options` as the `fields` property. The fourth `rawTableName` parameter was entirely removed as it was effectively unused. `QueryInterface`s `dropEnum` `dropAllEnums` and `pgListEnums` are now ONLY available on the `PostgresQueryInterface` class, they were previously no-ops when using any other dialog.
dfb0d32 to
6f8bbe5
Compare
|
@sushantdhiman I'm off for tonight, feel free to make any amends to this PR as you see fit directly rather than through comment, I will look at any changes tomorrow. |
| * | ||
| * @override | ||
| */ | ||
| async dropTable(tableName, options) { |
|
|
||
| class SQLiteQueryInterface extends QueryInterface { | ||
| /** | ||
| * A wrapper that fixes SQLite's inability to remove columns from existing tables. |
There was a problem hiding this comment.
This comment needs improvement as well
| const instanceTable = this.sequelize.modelManager.getModel(tableName, { attribute: 'tableName' }); | ||
|
|
||
| if (!instanceTable) { | ||
| // throw error?? |
There was a problem hiding this comment.
Oh yea, a comment here would be appreciated.
There was a problem hiding this comment.
Not sure, this case is for Migrations where models may not be available. So can't throw here. Ideally low level API's should not be aware of models.
|
Fantastic work, @SimonSchick !! |
| for (let i = 0; i < keyLen; i++) { | ||
| if (instanceTable.rawAttributes[keys[i]].type instanceof DataTypes.ENUM) { | ||
| const sql = this.queryGenerator.pgEnumDrop(getTableName, keys[i]); | ||
| options.supportsSearchPath = false; |
There was a problem hiding this comment.
Looks like options are optional here, so if you invoke Model.drop without options, there will be the error:
TypeError: Cannot set property 'supportsSearchPath' of undefined
at PostgresQueryInterface.dropTable (node_modules/sequelize/lib/dialects/postgres/query-interface.js:237:36)
at process._tickCallback (internal/process/next_tick.js:68:7)
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
Note:
The idea of this PR is to de-couple the dialects from the core query interface.
This reduces overhead as not all dialects required certain pre-computing that was performed in some places.
Some of these
breaking changesare not really breaking due to not being in the official API but better safe than sorry.Many of the postgres specific query interface APIs were never documented, should they?
Some of the changes (such as the rename of
QueryInterface -> queryInterfaceand the removal ofstackaren't strictly needed but do streamline the API.BREAKING CHANGE:
All instances of
QueryInterfaceandQueryGeneratorhave been renamed to their lowerCamelCase variants eg.queryInterfaceandqueryGeneratorwhen used as property names on Model and Dialect, the class names remain the same.Utils.stackhas been removed.QueryInterfaceis now an abstract class.query-interface.jswas moved tolib/dialects/abstract/query-interfaceand the exports have been reduced toQueryInterface.defaultandmodule.exportsno longer refer to this class.QueryInterface.addConstraints now only takes 2 parameters,tableNameandoptions, previously the second parameter could be a list of column names to apply the constraint to, this list must now be passed inoptionsas thefieldsproperty.The fourth
rawTableNameparameter was entirely removed as it was effectively unused.