feat: emit Oracle-compatible builder SQL - #109
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the SQL builder/compiler to emit Oracle-compatible SQL, primarily by adjusting alias syntax, pagination clauses, and mutation support gaps (RETURNING / DEFAULT handling) so Oracle can compile/execute the same builder constructs as Postgres/SQLite.
Changes:
- Remove
ASfor table/VALUES source aliases (Oracle rejectsASfor table aliases) and adjust VALUES alias commentary accordingly. - Emit Oracle pagination syntax (
OFFSET … ROWS+FETCH FIRST/NEXT … ROWS ONLY) and remove top-level query parentheses during compilation to avoid Oracle parser inconsistencies. - Extend insert behavior to support Oracle’s
DEFAULTkeyword for per-row values, add Oracle-specific “all-default insert” spelling, and explicitly reject.returning()for Oracle mutations until OUT binds are implemented.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/builder/values.ts | Updates VALUES alias documentation and minor formatting. |
| src/builder/update.ts | Omits AS for Oracle UPDATE aliases; rejects RETURNING for Oracle updates. |
| src/builder/sql.ts | Adds query-parenthesis metadata and unwraps top-level query parentheses in compile(). |
| src/builder/query.ts | Marks queries as parenthesized nodes; omits AS for table aliases; adds Oracle pagination emission. |
| src/builder/oracle.test.ts | Adds compile-time SQL shape tests for Oracle dialect output. |
| src/builder/oracle-live.test.ts | Adds optional live execution tests for Oracle (guarded by ORACLE_URL). |
| src/builder/insert.ts | Adds Oracle DEFAULT support, all-default insert spelling, Oracle alias clause handling, and rejects RETURNING. |
| src/builder/delete.ts | Omits AS for Oracle DELETE aliases; rejects RETURNING for Oracle deletes. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| const text = out.join(""); | ||
| return { | ||
| // Top-level parenthesized SELECTs are not consistently accepted by | ||
| // Oracle. Nested query nodes retain the wrapper because root then | ||
| // refers to their containing SQL node. | ||
| text: root.isParenthesizedQuery ? text.slice(1, -1) : text, | ||
| values, | ||
| }; |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 18 out of 18 changed files in this pull request and generated no new comments.
Suppressed comments (3)
src/builder/values.ts:35
- This comment also refers to a specific alias name (
q(...)). The emitted alias is determined by QueryBuilder’s registered alias (based on tsAlias, with potential suffixing), so the comment should describe the generic form.
// Return the pre-alias VALUES fragment. QB appends `q(col1, col2, ...)`.
src/builder/values.ts:9
- The comment mentions a hard-coded alias name (
q(...)), but Values uses whatever table alias QueryBuilder registers (typically derived from tsAlias, and can be suffixed on conflict). This is misleading when reading the code and when debugging compiled SQL.
This issue also appears on line 35 of the same file.
// VALUES emits `q(col1, col2, ...)` — column names go into the alias clause.
src/builder/update.ts:55
- The Oracle
.returning()unsupported error string is duplicated across insert/update/delete builders. Keeping this message in sync across mutation types is easy to miss and can lead to inconsistent behavior and tests.
const oracle = tableCls.database.dialect === "oracle";
if (oracle && returning) {
throw new Error(".returning() is not yet supported on oracle mutations");
}
5eea0d6 to
9d8301c
Compare
No description provided.