-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: move all dialect conditional logic into subclass #12217
Conversation
3052864
to
3734525
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using an abstract class for dialect specific query interface is more natural, so I am fine with this change. Let me know when this is ready for review
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice refactor
|
||
class SQLiteQueryInterface extends QueryInterface { | ||
/** | ||
* A wrapper that fixes SQLite's inability to remove columns from existing tables. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yea, a comment here would be appreciated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 test
ornpm run test-DIALECT
pass 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 changes
are 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 -> queryInterface
and the removal ofstack
aren't strictly needed but do streamline the API.BREAKING CHANGE:
All instances of
QueryInterface
andQueryGenerator
have been renamed to their lowerCamelCase variants eg.queryInterface
andqueryGenerator
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 tolib/dialects/abstract/query-interface
and the exports have been reduced toQueryInterface
.default
andmodule.exports
no longer refer to this class.QueryInterface.addConstraint
s now only takes 2 parameters,tableName
andoptions
, previously the second parameter could be a list of column names to apply the constraint to, this list must now be passed inoptions
as thefields
property.The fourth
rawTableName
parameter was entirely removed as it was effectively unused.