FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Where group by dpDesignz · Pull Request #186 · ezSQL/ezsql · GitHub

/ ezsql Public

Where group - #186

Merged
TheTechsTech merged 11 commits into
ezSQL:masterfrom
dpDesignz:where-group
Apr 24, 2020
Merged

Where group#186
TheTechsTech merged 11 commits into
ezSQL:masterfrom
dpDesignz:where-group

Conversation

dpDesignz commented Apr 21, 2020
edited
Loading

Copy link
Copy Markdown
Contributor

Resolves #164

UPDATE: There are no longer breaking changes

Example code from pdo\pdo_mysqlTest.php file:

$db->selecting(
    'unit_test', 
    '*', 
    where(
        eq('active', '1'),
        whereGroup(
           like('test_key', '%1%', _OR),
           like('test_key', '%3%')
        )
    )
);

or another example without the function

$db->selecting(
    'unit_test', 
    '*', 
    where(
        eq('active', '1'),
        like('test_key', '%1%', _OR, '('),
        like('test_key', '%3%', null, ')')
    )
);

The combiner will add itself at the end of the group.

Created the initial function but came across an issue where the $whereClause doesn't work in the $where method when using an OR combiner, so need to fix that first
Methods and functions complete but failed testing in phpunit so needing to fix
PHPUnit tests succeeded.
Cleaned up trailing combiner in tests
Comment thread lib/ezFunctions.php Outdated
* Creates an equality comparison expression with the given arguments.
*/
function eq($x, $y, $and = null, ...$args)
function eq($x, $y, $and = null, $group = null, ...$args)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Method eq has 5 arguments (exceeds 4 allowed). Consider refactoring.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

All these bring in another required field? Whereas ...$args already covers that. You should try adding additional logic in the other methods instead to get the same results you are after.

The logic could be some kind of token/trigger word, to extract to get the desired action.
This is far beyond a breaking change, unnecessary, the logic should include a way for the current code to continue to work. The current tests should still pass.

Comment thread lib/ezFunctions.php Outdated
* Creates a non equality comparison expression with the given arguments.
*/
function neq($x, $y, $and = null, ...$args)
function neq($x, $y, $and = null, $group = null, ...$args)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Method neq has 5 arguments (exceeds 4 allowed). Consider refactoring.

Comment thread lib/ezFunctions.php Outdated
* Creates the other non equality comparison expression with the given arguments.
*/
function ne($x, $y, $and = null, ...$args)
function ne($x, $y, $and = null, $group = null, ...$args)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Method ne has 5 arguments (exceeds 4 allowed). Consider refactoring.

Comment thread lib/ezFunctions.php Outdated
* Creates a lower-than comparison expression with the given arguments.
*/
function lt($x, $y, $and = null, ...$args)
function lt($x, $y, $and = null, $group = null, ...$args)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Method lt has 5 arguments (exceeds 4 allowed). Consider refactoring.

Comment thread lib/ezFunctions.php Outdated
* Creates a lower-than-equal comparison expression with the given arguments.
*/
function lte($x, $y, $and = null, ...$args)
function lte($x, $y, $and = null, $group = null, ...$args)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Method lte has 5 arguments (exceeds 4 allowed). Consider refactoring.

Copy link
Copy Markdown
Contributor

you will need to come up with a solution for the bc, to have tests pass as is.

Changed from breaking changes to use the existing extra `$args`. All existing PHPUnit tests run without failing.
Comment thread lib/ezFunctions.php Outdated
: false;
}

function flattenWhereConditions($whereConditions)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Function flattenWhereConditions has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This function should be in the class method being used in. It's a private helper function that should not be called directly by user/developer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Very good point. I have moved this to the ezQuery file as a private method.

Comment thread lib/ezQuery.php Outdated
}
}

public function whereGroup(...$whereConditions)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Function whereGroup has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

What you think about just calling it group or grouping?
The only place it can be used in is with where already.
Repeating the same word within the same function call trying to stay away from, and keep naming somewhat similar to regular SQL dialect.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Good idea. Have updated the code and tests. I didn't want to call it group as that felt too close to groupBy for me and I thought it might get confused, but I like grouping.

Incorrectly made a modification to the return of the `where` method instead of the `whereGroup` method

Copy link
Copy Markdown
Contributor Author

you will need to come up with a solution for the bc, to have tests pass as is.

Thanks, I didn't even really think of using the existing $args, that makes way more sense. It took me most of the day to work out how it worked in the first place. Definitely learned a lot. 😄

Updated the code to use the existing options to avoid breaking changes.

Copy link
Copy Markdown
Contributor

You will need to re-sync with master branch, the CI travis and appveyor systems and github see a conflicting file, and Travis still has a fail.

Copy link
Copy Markdown
Contributor Author

You will need to re-sync with master branch, the CI travis and appveyor systems and github see a conflicting file, and Travis still has a fail.

Thanks. Still learning how this all works with open source and larger projects. I've only really used GitHub for small personal projects until recently.

Both CI checks passed :)

Changed the method from `whereGroup` to `grouping` and moved the flatten function to be a private method in the `ezQuery` file as per @techno-express recommendations.
Comment thread lib/ezQuery.php
}
}

public function grouping(...$whereConditions)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Function grouping has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.

Added a brief example in the readme file underneath the shortcut methods. Will add a detailed example in the wiki once approved.
TheTechsTech merged commit c843017 into ezSQL:master Apr 24, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

Grouping WHERE conditions with ezSQL v4 PDO

2 participants


Back | FazBrowse Home | New Git URL