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

Make all query building methods append-only #61

Open
shadowhand opened this issue May 1, 2018 · 2 comments
Open

Make all query building methods append-only #61

shadowhand opened this issue May 1, 2018 · 2 comments
Milestone

Comments

@shadowhand
Copy link
Owner

Refer to changes make in #58; the following methods should be modified:

  • Merge functionality of addColumns() into columns()
  • Merge functionality of addFrom() into from()
@shadowhand shadowhand added this to the 4.0.0 milestone May 1, 2018
@riseoflex88
Copy link

The ability to add a column or overwrite all is good functionality.

I can think of a good case where this wouldn't be a desired change, if you wanted to run a query i.e. a complex search with a limit of 10 results. But you need to show the total number of results too.

So Query A contains the full query:

$queryA = $builder->select(a.*, b*)
               ->from('a'...
               ->join('b'...
               ->join('c'...
               ->where...
               ->limit(10)
               ->offset(0)

Query B is almost entirely the same query, minus the limit / offset and swapping the select for a count

$queryB = $queryA->columns(fn('COUNT', 'a.id'));
               ->limit(null)
               ->offset(null)

This would then allow a streamlined way of displaying "Showing results 10 of 1000".

If the columns functionality only supported appending, the query would be vastly less efficient.

Keeping addColumns and Columns as separate functions makes perfect sense to me

@shadowhand shadowhand modified the milestones: 4.0.0, 5.0.0 Aug 10, 2019
@pavarnos
Copy link
Contributor

Yes. This is valuable for pagination: Pass the full SelectQuery to the paginator and it generically create the COUNT query from any other.

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

No branches or pull requests

3 participants