Make all query building methods append-only
Refer to changes make in #58; the following methods should be modified:
- Merge functionality of
addColumns()intocolumns() - Merge functionality of
addFrom()intofrom()
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
Yes. This is valuable for pagination: Pass the full SelectQuery to the paginator and it generically create the COUNT query from any other.