Skip to content

fix(d1): preserve unary operators in processCol to support leading + and - - #63

Merged
treeder merged 2 commits into
mainfrom
debug_sqlite_syntax_error
Sep 3, 2026
Merged

fix(d1): preserve unary operators in processCol to support leading + and -#63
treeder merged 2 commits into
mainfrom
debug_sqlite_syntax_error

Conversation

@treeder

@treeder treeder commented Sep 3, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes an issue where column identifiers with leading unary operators (e.g. +threads.showAt or -threads.score) were mangled by processCol() into invalid SQL like json_extract(threads.+threads, '$.showAt'), causing SQLite near "+": syntax error.

What changed

  • In processCol(), extract any leading unary operator (+ or -) before running prefixing and JSON sub-property extraction, then reattach it to the resulting column expression.
  • Added tests in test/test_order.test.js covering:
    • Query integration tests sorting with +users.name and (+users.name).
    • Unit tests asserting processCol behavior with qualified and unqualified unary expressions and JSON paths.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📋 Review Summary

This pull request adds support for leading unary operators (such as + and -) in D1.processCol, preventing unary operators from interfering with table prefixing or SQLite JSON path extraction during query ordering. It also introduces unit and integration tests covering unary operator handling. However, the assertions for test case 4 in test/test_order.test.js were accidentally removed during the update and should be restored.

🔍 General Feedback

  • Preserving leading unary operators in processCol cleanly enables SQLite idioms like unary + (to suppress index utilisation) and unary - (for inverted sorting).
  • The defensive typeof col !== 'string' check added at the beginning of processCol is a good addition to prevent runtime type errors if non-string values are passed.
📊 Token Usage & Cost Efficiency
Metric Value
Input Tokens (uncached) 52,469
Output Tokens 479
Total Session Tokens 64,995
Cost (uncached input) $0.0394
Cost (output) $0.0018
Estimated Total Cost $0.0411

Gemini 3.8 Flash: introductory rate $0.75/$3.75 per 1M applied; reverts to $1.5/$7.5 after 2026-12-31.
Gemini 3.8 Flash: standard tier; batch and flex are half again, priority is higher.

Comment thread test/test_order.test.js
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@treeder
treeder merged commit 383b995 into main Sep 3, 2026
1 check passed
@treeder
treeder deleted the debug_sqlite_syntax_error branch September 3, 2026 19:43
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