Generic constraint contexts for queries #55

Closed
opened 7 years ago by jking · 0 comments
jking commented 7 years ago
Owner

Article-related methods such as articleList and editionLatest and well as subscriptionList are starting to have significantly complex input; using method parameters would be a mess, and using a data array as update methods do would be fraught with bugs, not to mention awkward syntax.

The best way to address this may be to introduce a Context class which the caller can build and the called method then inspect with less pain than an associative array. Building the context might go something like this:

$context = (new Context)
    ->folder(4) // only articles/subscriptions within folder #4
    ->subscription(5) // only articles within subscription #5
    ->feed(10) // only articles within feed #10
    ->latestEdition(394) // only articles equal or less than edition #394
    ->oldestEdition(394) // only articles newer than edition #394
    ->modifiedSince($time) // only articles newer than a given time
    ->modifiedBefore($time) // only articles equal or older than a given time
    ->unread(true) // only unread articles
    ->read(true) // only read articles
    ->starred(true) //only starred articles
    ->unstarred(true) // only unstarred articles
    ->limit(5) // return no more than 5
    ->offset(10) //skip the first 10 results
    ->reversed(true); // return results in inverse order from whatever is usual

Obviously not all constraints will make sense for a given query. The method in question would probably have to handle each constraint separately regardless because the query would need to be constructed differently for different selection aims; the Context class should make this handling as painless as possible, however.

Article-related methods such as `articleList` and `editionLatest` and well as `subscriptionList` are starting to have significantly complex input; using method parameters would be a mess, and using a data array as update methods do would be fraught with bugs, not to mention awkward syntax. The best way to address this may be to introduce a `Context` class which the caller can build and the called method then inspect with less pain than an associative array. Building the context might go something like this: ```php $context = (new Context) ->folder(4) // only articles/subscriptions within folder #4 ->subscription(5) // only articles within subscription #5 ->feed(10) // only articles within feed #10 ->latestEdition(394) // only articles equal or less than edition #394 ->oldestEdition(394) // only articles newer than edition #394 ->modifiedSince($time) // only articles newer than a given time ->modifiedBefore($time) // only articles equal or older than a given time ->unread(true) // only unread articles ->read(true) // only read articles ->starred(true) //only starred articles ->unstarred(true) // only unstarred articles ->limit(5) // return no more than 5 ->offset(10) //skip the first 10 results ->reversed(true); // return results in inverse order from whatever is usual ``` Obviously not all constraints will make sense for a given query. The method in question would probably have to handle each constraint separately regardless because the query would need to be constructed differently for different selection aims; the `Context` class should make this handling as painless as possible, however.
jking referenced this issue from a commit 7 years ago
jking closed this issue 7 years ago
jking added this to the 0.1.0 milestone 7 years ago
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.