-
Notifications
You must be signed in to change notification settings - Fork 444
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
Introduce interface for entity querybuilders #5354
Comments
- Add interface methods for getting a query builder, counting rows, and getting a list of IDs. - Add methods to EntityReadInterface to provide Service-level access to these queries. - Change some instances of service class usage to use Services::get() rather than assigning the service to a variable. This is done for consistency.
- Add interface methods for getting a query builder, counting rows, and getting a list of IDs. - Add methods to EntityReadInterface to provide Service-level access to these queries. - Change some instances of service class usage to use Services::get() rather than assigning the service to a variable. This is done for consistency.
After some time, the trait did not get much use. It appears to be an abstraction with little benefit, so I've taken the one method and put the code inline wherever it is used.
- Add interface methods for getting a query builder, counting rows, and getting a list of IDs. - Add methods to EntityReadInterface to provide Service-level access to these queries. - Change some instances of service class usage to use Services::get() rather than assigning the service to a variable. This is done for consistency.
See commit message in pkp-lib: b2fc266eb1495eec38b032498031bc51f1008c9e
PRs: @asmecher can you take a look at this and let me know if this looks alright? Some further details below. These PRs provide a new
The The result of $qb = new \APP\Services\QueryBuilders\UserQueryBuilder();
$qb->filterByContext($contextId);
// Get all matching emails
$emails = $qb->getQuery()->pluck('u.email');
// Get the first matching result
$user = $qb->getQuery()->first();
// Get the last registered user
$user = $qb->getQuery()->max('u.date_registered'); Documentation on the Laravel 5.5 Query Builder. Our Service classes have also been extended to expose this functionality to third-party users. The (Side note: I think naming our classes QueryBuilders is a bit confusing since that's what Laravel calls its implementation as well. It is probably worth consider a new name for our convention. In many ways these could grow to merge with our DAOs, but that's a discussion for a later date.) |
That looks like a sensible cleanup to me, Nate, thanks! I see some room for improvement around the pagination stuff -- that's another case where I'd love to get rid of our old home-grown stuff entirely -- but let's come back to that along with more discussion about e.g. DAO vs. query builder etc. |
- Add interface methods for getting a query builder, counting rows, and getting a list of IDs. - Add methods to EntityReadInterface to provide Service-level access to these queries. - Change some instances of service class usage to use Services::get() rather than assigning the service to a variable. This is done for consistency.
After some time, the trait did not get much use. It appears to be an abstraction with little benefit, so I've taken the one method and put the code inline wherever it is used.
- Add interface methods for getting a query builder, counting rows, and getting a list of IDs. - Add methods to EntityReadInterface to provide Service-level access to these queries. - Change some instances of service class usage to use Services::get() rather than assigning the service to a variable. This is done for consistency.
See commit message in pkp-lib: b2fc266eb1495eec38b032498031bc51f1008c9e
- Add interface methods for getting a query builder, counting rows, and getting a list of IDs. - Add methods to EntityReadInterface to provide Service-level access to these queries. - Change some instances of service class usage to use Services::get() rather than assigning the service to a variable. This is done for consistency.
After some time, the trait did not get much use. It appears to be an abstraction with little benefit, so I've taken the one method and put the code inline wherever it is used.
- Add interface methods for getting a query builder, counting rows, and getting a list of IDs. - Add methods to EntityReadInterface to provide Service-level access to these queries. - Change some instances of service class usage to use Services::get() rather than assigning the service to a variable. This is done for consistency.
See commit message in pkp-lib: b2fc266eb1495eec38b032498031bc51f1008c9e
- Add interface methods for getting a query builder, counting rows, and getting a list of IDs. - Add methods to EntityReadInterface to provide Service-level access to these queries. - Change some instances of service class usage to use Services::get() rather than assigning the service to a variable. This is done for consistency.
After some time, the trait did not get much use. It appears to be an abstraction with little benefit, so I've taken the one method and put the code inline wherever it is used.
- Add interface methods for getting a query builder, counting rows, and getting a list of IDs. - Add methods to EntityReadInterface to provide Service-level access to these queries. - Change some instances of service class usage to use Services::get() rather than assigning the service to a variable. This is done for consistency.
See commit message in pkp-lib: b2fc266eb1495eec38b032498031bc51f1008c9e
- Add interface methods for getting a query builder, counting rows, and getting a list of IDs. - Add methods to EntityReadInterface to provide Service-level access to these queries. - Change some instances of service class usage to use Services::get() rather than assigning the service to a variable. This is done for consistency.
See commit message in pkp-lib: b2fc266eb1495eec38b032498031bc51f1008c9e
- Add interface methods for getting a query builder, counting rows, and getting a list of IDs. - Add methods to EntityReadInterface to provide Service-level access to these queries. - Change some instances of service class usage to use Services::get() rather than assigning the service to a variable. This is done for consistency.
See commit message in pkp-lib: b2fc266eb1495eec38b032498031bc51f1008c9e
Query builders for entities can and should handle data retrieval whenever full objects are not required. This is in cases like getting a count of objects or retrieving all the IDs that match a set of filters.
To keep the query builders aligned, they should implement an interface with four methods. The first method,
_getQueryObject
, is a protected method which constructs the filter criteria for the query -- thewhere
,leftJoin
, etc conditions. It will be used by the other three methods, which offer distinct select criteria:getQuery
will return a query object that can be passed to the DAO'sretrieveRange
method to be used for getting a collection of objects.count
will return a count of the rows which match the query.getIds
will return an array of the entity ids which match the query.This will allow more of Laravel's querybuilder syntax to be used to generate useful queries. First we define the query builder conditions (same as before):
Then we can use the same query conditions to retrieve different things:
The query object that
getQuery
will return can be executed with Laravel'sget()
and then used alongside other features of Laravel's querybuilders to get other kinds of results. In this case, we want an array of titles:The text was updated successfully, but these errors were encountered: