Skip to content

Implement feature request #30 — Support UNION (fix)#38

Merged
liquid207 merged 1 commit intomasterfrom
feat/issue-30
Mar 24, 2026
Merged

Implement feature request #30 — Support UNION (fix)#38
liquid207 merged 1 commit intomasterfrom
feat/issue-30

Conversation

@liquid207
Copy link
Collaborator

@liquid207 liquid207 commented Mar 24, 2026

This PR adds basic support for SQL UNION / UNION ALL in the Converter.

Changes:

  • Add detection and handling of top-level SetOperation/SetExpr in src/converter.js
  • Convert left/right subqueries to query builder expressions and chain with ->union/->unionAll
  • Pass right-side as DB::table(...) block so output matches expected Eloquent syntax
  • Append top-level order_by and get() when present

Test case (from issue #30):

SQL:
(select * from users where last_name is null) union all (select * from users where first_name is null)

Expected Eloquent output:

DB::table('users')
->whereNull('last_name')
->unionAll(
 DB::table('users')
 ->whereNull('first_name')
)
->orderBy('id')
->get();

What I changed and why:

  • Previously the converter passed the right-hand side as a closure variant that produced incorrect formatting. Now the right-hand side is emitted as a DB::table(...) expression block and passed directly to ->union/->unionAll so the chain looks like the expected Eloquent builder usage.

Notes / Limitations:

  • This initial fix covers common top-level UNION / UNION ALL usage. More complex nested set operations or mixing of different select column lists may need additional handling.

Please run the test suite or try the SQL above in the demo to verify. If you want, I can add an automated unit test for this case in tests/ and push it to this branch.

@liquid207 liquid207 merged commit f54cab2 into master Mar 24, 2026
@sql2builder sql2builder changed the title Implement feature request #30 — Support UNION Implement feature request #30 — Support UNION (fix) Mar 24, 2026
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.

1 participant