Skip to content

Improve Sql class to work with shape detection#98

Merged
alganet merged 1 commit into
Respect:masterfrom
alganet:new-sql
Mar 18, 2026
Merged

Improve Sql class to work with shape detection#98
alganet merged 1 commit into
Respect:masterfrom
alganet:new-sql

Conversation

@alganet

@alganet alganet commented Mar 18, 2026

Copy link
Copy Markdown
Member

Replace the old Sql builder with a shape-detection architecture that auto-detects SQL clause type from argument structure instead of relying on method-name dispatch tables and string concatenation.

Conditions now use explicit triplet syntax ['column', 'operator', value] with inline 'AND'/'OR' operators and nested grouping via arrays, replacing the old associative-array-with-operator-in-key convention and the underscore grouping methods (and_/or_/_).

Key changes in src/Sql.php:

  • Shape-based __call dispatch into named private methods (commaList, namedList, rawPairs, paramPairs, valueList, conditions)
  • Triplet condition rendering (scalarTriplet, subqueryTriplet, expandTriplet) with declarative EXPAND constant for IN/NOT IN/BETWEEN
  • RAW constant for instructions where assoc values are identifiers (on)
  • Sql::raw() for unparameterized expressions (NOW(), counter + 1)
  • concat() replaces appendQuery() for query composition
  • Structured column definitions ['id', 'INT', 'PRIMARY KEY'] in DDL
  • Full PHPStan compliance with no mixed, no @var inlines, no ignores

Key changes in consumers:

  • Db: removed query() raw SQL escape hatch
  • Mapper: triplet conditions in parseConditions/guessCondition, array_keys/array_values split for insertInto/values, spread operator for select, concat() for extra clauses
  • Tests rewritten for triplet syntax with expanded coverage (IN, BETWEEN, NOT IN, subqueries, raw expressions, DDL, DCL)

@alganet alganet marked this pull request as ready for review March 18, 2026 19:32
@alganet alganet requested a review from Copilot March 18, 2026 19:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR replaces the previous string/dispatch-table SQL builder with a shape-detection–based Sql builder, updating consumers and tests to use triplet-style conditions and new query composition.

Changes:

  • Reworked Sql into a shape-based __call/__callStatic dispatcher supporting triplet conditions, list formatting, raw expressions, and concat() composition.
  • Updated Mapper and Db to use the new builder patterns (triplet conditions, concat(), and removal of Db::query()).
  • Rewrote/expanded tests to cover the new condition syntax, subqueries, raw expressions, and DDL/DCL builders.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/Sql.php New shape-detection SQL builder implementation (lists, triplets, raw, concat, expand operators).
src/Mapper.php Migrates Mapper query construction to triplet conditions and new builder APIs.
src/Db.php Removes the raw SQL query() escape hatch and relies on fluent SQL builder usage.
tests/SqlTest.php Updates and expands test coverage for the new Sql API and syntax.
tests/DbTest.php Updates Db tests to avoid query() and use fluent builder with triplet conditions.
tests/MapperTest.php Updates fixture inserts to new insert API and adjusts condition-based fetch tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/Sql.php
Comment thread src/Sql.php
Comment thread src/Sql.php
Comment thread src/Mapper.php
Comment thread tests/SqlTest.php
Replace the old Sql builder with a shape-detection architecture that
auto-detects SQL clause type from argument structure instead of
relying on method-name dispatch tables and string concatenation.

Conditions now use explicit triplet syntax ['column', 'operator', value]
with inline 'AND'/'OR' operators and nested grouping via arrays,
replacing the old associative-array-with-operator-in-key convention
and the underscore grouping methods (and_/or_/_).

Key changes in src/Sql.php:
- Shape-based __call dispatch into named private methods (commaList,
  namedList, rawPairs, paramPairs, valueList, conditions)
- Triplet condition rendering (scalarTriplet, subqueryTriplet,
  expandTriplet) with declarative EXPAND constant for IN/NOT IN/BETWEEN
- RAW constant for instructions where assoc values are identifiers (on)
- Sql::raw() for unparameterized expressions (NOW(), counter + 1)
- concat() replaces appendQuery() for query composition
- Structured column definitions ['id', 'INT', 'PRIMARY KEY'] in DDL
- Full PHPStan compliance with no mixed, no @var inlines, no ignores

Key changes in consumers:
- Db: removed query() raw SQL escape hatch
- Mapper: triplet conditions in parseConditions/guessCondition,
  array_keys/array_values split for insertInto/values,
  spread operator for select, concat() for extra clauses
- Tests rewritten for triplet syntax with expanded coverage
  (IN, BETWEEN, NOT IN, subqueries, raw expressions, DDL, DCL)
@alganet alganet merged commit c973649 into Respect:master Mar 18, 2026
3 checks passed
@alganet alganet deleted the new-sql branch March 18, 2026 19:55
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.94521% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.09%. Comparing base (4d481bb) to head (33d795c).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/Mapper.php 88.23% 2 Missing ⚠️
src/Sql.php 99.22% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master      #98      +/-   ##
============================================
- Coverage     98.63%   98.09%   -0.54%     
- Complexity      192      200       +8     
============================================
  Files             3        3              
  Lines           513      526      +13     
============================================
+ Hits            506      516      +10     
- Misses            7       10       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants