The Wayback Machine - http://web.archive.org/web/20201109041714/https://github.com/ezSQL/ezsql/pull/186
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

Where group #186

Merged
merged 11 commits into from Apr 24, 2020
Merged

Where group #186

merged 11 commits into from Apr 24, 2020

Conversation

@dpDesignz
Copy link
Contributor

@dpDesignz dpDesignz commented Apr 21, 2020

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.

dpDesignz added 4 commits Apr 21, 2020
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
@@ -126,110 +127,110 @@ function createCertificate(
/**
* 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)

This comment has been minimized.

@codeclimate

codeclimate bot Apr 21, 2020

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

This comment has been minimized.

@techno-express

techno-express Apr 21, 2020
Contributor

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.

return $expression;
}

/**
* 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)

This comment has been minimized.

@codeclimate

codeclimate bot Apr 21, 2020

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

return $expression;
}

/**
* 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)

This comment has been minimized.

@codeclimate

codeclimate bot Apr 21, 2020

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

return $expression;
}

/**
* 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)

This comment has been minimized.

@codeclimate

codeclimate bot Apr 21, 2020

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

return $expression;
}

/**
* 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)

This comment has been minimized.

@codeclimate

codeclimate bot Apr 21, 2020

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

@techno-express
Copy link
Contributor

@techno-express techno-express commented Apr 21, 2020

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.
@@ -485,6 +493,19 @@ function replace($table = '', $keyValue)
: false;
}

function flattenWhereConditions($whereConditions)

This comment has been minimized.

@codeclimate

codeclimate bot Apr 22, 2020

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

This comment has been minimized.

@techno-express

techno-express Apr 23, 2020
Contributor

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.

This comment has been minimized.

@dpDesignz

dpDesignz Apr 23, 2020
Author Contributor

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

}
}

public function whereGroup(...$whereConditions)

This comment has been minimized.

@codeclimate

codeclimate bot Apr 22, 2020

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

This comment has been minimized.

@techno-express

techno-express Apr 23, 2020
Contributor

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.

This comment has been minimized.

@dpDesignz

dpDesignz Apr 23, 2020
Author Contributor

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
@dpDesignz
Copy link
Contributor Author

@dpDesignz dpDesignz commented Apr 22, 2020

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.

@techno-express
Copy link
Contributor

@techno-express techno-express commented Apr 22, 2020

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.

dpDesignz added 3 commits Apr 22, 2020
Synced with master branch to reduce conflicts
Synced with master branch to reduce conflicts
@dpDesignz
Copy link
Contributor Author

@dpDesignz dpDesignz commented Apr 22, 2020

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.
}
}

public function grouping(...$whereConditions)

This comment has been minimized.

@codeclimate

codeclimate bot Apr 23, 2020

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.
@techno-express techno-express merged commit c843017 into ezSQL:master Apr 24, 2020
3 checks passed
3 checks passed
codeclimate 1 fixed issue
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants
You can’t perform that action at this time.