QB Extention - #2
Open
enlivenapp wants to merge 1 commit into
Open
enlivenapp wants to merge 1 commit into
enlivenapp wants to merge 1 commit into
Conversation
…, groups, HAVING, unions, batch writes, BC compat preserved.
Added:
- selectSum/selectAvg/selectMin/selectMax/selectCount with optional alias
- distinct()
- selectSubquery()/fromSubquery() with correctly ordered parameters
- whereIn/orWhereIn/whereNotIn/orWhereNotIn (array or subquery Builder)
- like/orLike/notLike/orNotLike (value bound as LIKE ?, wildcards escaped, explicit ESCAPE '!', positions both/before/after/none)
- groupStart/orGroupStart/notGroupStart/groupEnd with unbalanced-group error
- having()/orHaving()
- rightJoin()
- union()/unionAll()
- insertBatch()/upsertBatch()/updateBatch()/deleteBatch()
- when()/whenNot()
- build(bool $reset = false) opt-in reset
- orderBy($column, ?string $direction = null) validated second form (safeIdentifier + ASC/DESC)
- tests/BuilderExtensionsTest.php, tests/QueryLoggerTest.php, tests/QueryPanelTest.php, BuilderRaw::__toString coverage
Fixed:
- count() no longer leaks select-subquery params into COUNT (placeholder/param mismatch)
- count() emits JOIN clauses again (restore original behavior)
- delete() no longer uses fromSubquery (was emitting invalid DELETE FROM (subquery) and dropping params)
- QueryLogger metric-key guard so new batch actions don't warn on unknown keys
- updateBatch() missing-WHERE-column test now exercises the intended check
Changed:
- WHERE conditions stored as structured {join, sql} parts to support groups and HAVING
- buildSQL() now shares compileSelect() with build()
- clearAll() clears the new builder state (selectParams/fromParams/having/unions/distinct/fromSubquery/batch)
See CHANGELOG.md and README.md for more details.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Alrighty... what a minefield. lol
As we discussed in #1 here's what I've done as I understand what you were interested in seeing and wanted, if I missed anywhere, please let me know and I'll get it fixed. I parked the CHANGELOG list in
Unreleasedso I'm not guessing.Select / aggregates
selectSum(),selectAvg(),selectMin(),selectMax(),selectCount()with optional aliasdistinct()selectSubquery(Builder, $alias = '')andfromSubquery(Builder, $alias)(alias required) with correctly ordered parametersConditions
whereIn(),orWhereIn(),whereNotIn(),orWhereNotIn(): accept an array or a subqueryBuilderlike(),orLike(),notLike(),orNotLike(): value is bound (LIKE ?), wildcards escaped, explicitESCAPE '!'; positionsboth/before/after/none. Existing['LIKE', ...]array form is untouched.groupStart(),orGroupStart(),notGroupStart(),groupEnd(): balanced, helpful error on unbalancedhaving(),orHaving()Joins / unions
rightJoin()union(),unionAll()Writes
insertBatch(),upsertBatch(),updateBatch(),deleteBatch()Builder
when(),whenNot()build(bool $reset = false): opt-in reset (default behavior unchanged)orderBy($column, ?string $direction = null): second form validates the column withsafeIdentifier()and restricts direction toASC/DESC; the existing single-argument expression form still works. Multiple calls replace (same for both forms).Misc
Things I ran across while building this that you might want to lay eyes on and decide if you want to do anything with. I've left all of it alone.
getParams()is unchanged. It still returns only WHERE-bound parameters and does not include the new-feature params (data,HAVING, select-subqueries,UNION). The full list is always inbuild()['params']. I left it as-is for BC rather than change its return value; if you'd rather it matchbuild()['params'], that's a separate change.clearAll()still preserves the action. The newbuild(true)clears then resets the action toSELECTas an extra step, so the opt-in reset is fully reusable. Documented in the README plus a dedicated test.QueryLogger/ Tracy panel: the loggedwhereremainsarray<string>and the panel rendering is unchanged, for BC. Consequence: grouped conditions (groupStart()etc.) render imperfectly in the debug panel (implode(' AND ')over(...)). Debug only, no SQL impact.upsertBatch()emitsVALUES(col), matching the existingonDuplicateKeyUpdate()docs. That form is deprecated in MySQL 8.0.20+ in favor of row aliases, so switch it if you want the newer syntax.insertBatch()/upsertBatch()require every row to have identical columns in the same order (rejects ambiguity rather than silently reordering).Internal changes (no output change for existing usage)
{join, sql}) to support nesting andHAVING; parameter assembly is centralized so SELECT subquery/FROM/HAVING/UNION params stay in SQL order.buildSQL()now shares the SELECT compiler (compileSelect()) withbuild(); identical output for pre-existing inputs, plusDISTINCT/HAVING/subqueries when those features are used.QueryLoggergained a null-coalescing metric-key guard so the new batch actions don't warn on unknown keys.Testing
composer test: 175 tests(+36), 345 assertions(+85), 1 environment-skipped (the "logging disabled" panel branch needs Tracy absent).composer phpstan: at level-max.Builder99.10%,BuilderRaw100%,QueryLogger100%,QueryPanel98.26%. I've pulled coverage up as high as reasonably possible.