Skip to content
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

add MSSQL support (requested changes) #33

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

ojourmel
Copy link

@ojourmel ojourmel commented Aug 27, 2017

Refactor mssql dialect as per pull #26 feedback

This pull request is a continuation of #26. I used @iteufel's work, implemented the changes requested, and improved the test coverage.

  • Include all test files in gulp lint tasks
  • Move mssql value block override to blocks.js
  • Update mssql limit block to use _.isUndefined
  • Clean up minor mssql sql letter case and format
  • Set the mssql identifier prefix and suffix

There are two changes to the base dialect.

  • Refactor the base insert:values block function to clean up the logic (match the mssql inserted:values block function)
  • Update buildTemplate to include an edge case where a buildBlock function does not return any values. This prevents unnecessary whitespace in the final query string.

These changes are not strictly necessary. The mssql insert:values block could use the same structure as the original base block, and unnecessary whitespace has no issues in terms of functionality, simply aesthetics.


I will self review this pull request to record, and address the feedback given on #26
Let me know if this pull request is appropriate, or if there is anything I can help clean up.

Thanks for this great library!

iteufel and others added 9 commits August 20, 2017 22:13
Mssql is now using builder._pushValue for limit/offset
Replaced whitspaces with tabs
Replaced spaces with tabs
Reverted package.json
This commit refactors the `mssql` dialect as per the feedback
from @artzhookov on 2do2go#26.

 - Include all test files in gulp lint tasks
 - Move mssql `value` block override to blocks.js
 - Update mssql `limit` block to use `_.isUndefined`
 - Clean up minor mssql sql letter case and format
 - Set the `mssql` `identifier` `prefix` and `suffix`

This commit also introduces two changes to the `base` dialect.
 - Refactor the `base `insert:values` `block` function to clean up
   the logic
 - Refactor the `mssql` `inserted:values` `block` function to match
   the `base` function, and also include `returning` params, as it
   is needed. (mssql puts `output` keyword before `values` keyword)
 - Update `buildTemplate` to include an edge case where a `buildBlock`
   function does not return any value. This prevents unnecessary
   whitespace in the final query string.

These changes are not strictly necessary. The `mssql` `insert:values` `block`
could use the same structure as the original `base` `block`, and unnecessary
whitespace has no issues in terms of functionality, simply ascetics.

This commit refactors the `mssql` tests as per the changes made.
Test coverage and layout is not ideal, but functional.
This commit updates the tests for the `mssql` dialect
to improve coverage. Additionally, some refactoring is done
to the `mssql` dialect to remove unnecessary code.
Copy link
Author

@ojourmel ojourmel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linked and addressed relevant comments from pull #26

module.exports = function(dialect) {
var parentValueBlock = dialect.blocks.get('value');

dialect.blocks.set('value', function(params) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#26 (comment)

Logic moved from builder._pushValue to blocks.js. number, string, and null/undefined cases are handled by parentValueBlock(params) I belive.


dialect.blocks.set('limit', function(params) {
var result = '';
if (_.isUndefined(params.offset)) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#26 (comment)

_.isUndefined used.

});

dialect.blocks.set('offset', function(params) {
var prefix = (!params.sort) ? 'order by 1 ' : '';
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#26 (comment)
#26 (comment)

This function was refactored to clean up the program flow. offset case fixed

});

dialect.blocks.set('insert:values', function(params) {
var values = params.values;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#26 (comment)

This function was refactored a little bit, as was the base blocks.js. This cleans up the values and fields variable assignment.

returning is needed here, because it is used in the next buildTemplate call. {returning} is now part of the insertValues template. See template

#26 (comment)
The unnecessary code was removed

@artzhookov artzhookov self-requested a review August 27, 2017 12:01
@ojourmel
Copy link
Author

Hi @artzhookov, is there anything I can do to help move this pull request along? Any additional testing, cases, or code quality you would like me to address?

Thanks for taking the time to look at this, it's a great little library!

@artzhookov
Copy link
Contributor

Hi @ojourmel, first of all thank you for your help!
Sorry for long response. Autumn is a very high loaded period =)
I think I'll be able to review your PR at the weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants