node-mysql-utilities
node-mysql-utilities copied to clipboard
Fix/query signature
trafficstars
Applying a fix for #59 . In other words, this pull request enables the usage of connection.query and similar methods with all possible mysql function signatures. This makes it possible to pass an options object to connection.query. Previously this was not possible because the function signature was fixed to only one case.
Implementation details:
- Making use of the mysql util function
createQuery. This function takes all possible signatures and produces the corresponding values by handling all cases as can be seen here. Moreover, the function already returns the input if it is already an instance ofQuery(already executedcreateQuery()) - Because of this
instanceof Querycheck, I had to turn the mysql dependency to a dev dependency and to a peer dependency. In this way we make sure that the instance of theQueryis the same instance that the consumers of this package are going to use. Especially important whenever themysqlpackage is occurring multiple times in the dependency tree of a consumer package. - I had to apply
/* eslint-disable no-use-before-define */because the new implementation explicitly makes use of the variable hoisting to make the callback wrappers work. - I have manually tested this new implementation in my own private repo which has multiple dependencies of mysql and
node-mysql-utilities.
Checks:
- [x] tests and linter show no problems (
npm t) - [x] tests are added/updated for bug fixes and new features
- [x] code is properly formatted (
npm run fmt)