- Notifications
You must be signed in to change notification settings - Fork689
Implement JavaScript property access in SQL queries#2372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:develop
Are you sure you want to change the base?
Conversation
- Add property access support for dot notation (name.length)- Detect when Column's tableid is actually a column name (not table)- Generate correct code for property access patterns- Enable and fix test341 tests 4 and 5- All 2085 tests passing (2 new tests enabled)Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
mathiasrw commentedDec 17, 2025
@copilot Continue |
Implementation complete! ✅ All acceptance criteria met:
The implementation detects property access patterns by checking if the first part of a dot expression is a column name rather than a table name, then generates safe JavaScript code with null-checking. Ready for merge. Commit:ceb4dfc |
| it.skip('5. JavaScript way',function(done){ | ||
| it('5. JavaScript way',function(done){ | ||
| varres=alasql('SELECT COLUMN name.length FROM persons'); | ||
| assert.deepEqual(res,[6,6,7]); | ||
| done(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Can we adda a test if I can name a table.col.length ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Added test fortable.column.length syntax! ✅
The three-level dot notation already works correctly with the current implementation. Added test "6. JavaScript way with table.column.length" that verifies:
SELECT COLUMN persons.name.length FROM persons→ [6, 6, 7]- Also works with aliases:
SELECT COLUMN p.name.length FROM persons AS p
All 2086 tests passing. Commit:ddb0088
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
- Add test "6. JavaScript way with table.column.length"- Verifies three-level dot notation works correctly- Tests SELECT COLUMN persons.name.length FROM persons- All 2086 tests passing (1 new test added)Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
Uh oh!
There was an error while loading.Please reload this page.
Implementation Plan for JavaScript Property Access in SQL
Implementation Summary
Successfully implemented JavaScript property access using dot notation in SQL queries. The implementation enables seamless JavaScript integration by allowing developers to access object properties directly within SQL statements.
Features Implemented ✅
"hello".length→ 5SET @a = "who".length→@A = 3SELECT COLUMN name.length FROM persons→ [6, 6, 7]SELECT COLUMN persons.name.length FROM persons→ [6, 6, 7]WHERE name.length > 6→ Works correctlyname->length→ Still works as beforetable.column→ Unchanged behaviorChanges Made
Property Access Detection (src/424select.js):
compileSelect1to detect when a Column'stableidis actually a column name (not a table)query.defcolsto determine if we're dealing with property access pattern (e.g.,name.length)((p['table']['column'] || {})['property'])Column.toJS Enhancement (src/50expression.js):
Column.toJSmethodtableidexists in defcols, treats it as property access patternTest Fixes (test/test341.js):
Test Results
Implementation Details
The solution detects when a Column reference pattern
A.Brepresents property access (column A, property B) rather than table.column access by checking ifAexists in thequery.defcolsdictionary, which maps column names to their source tables. IfAis a column, we generate safe JavaScript code with null-checking:((p['table']['column'] || {})['property']). Otherwise, we use the traditional table.column interpretation.The implementation also supports three-level dot notation like
table.column.propertywhich works seamlessly with the existing logic.Security Considerations
|| {}fallback->operator)Status: ✅ Complete and ready for merge
Original prompt
This section details on the original issue you should resolve
<issue_title>JavaScript Property Access in SQL - Object Property Navigation</issue_title>
<issue_description>Priority: 1 (Critical)
Impact: SQL-99 Compliance & JavaScript Integration
Test File:
test/test341.jsTest Location: Lines 38, 44
Test Names: "4. JavaScript way", "5. JavaScript way"
Problem Description
The tests
test341.jslines 38 and 44 contain skipped tests for JavaScript property access within SQL queries. These tests verify that AlaSQL can access JavaScript object properties and methods directly in SQL statements, providing seamless JavaScript integration.Specific Test Cases
Expected Behavior
These tests should verify:
Current Status
it.skip)Steps to Reproduce
test/test341.jsit.skip('4. JavaScript way'toit('4. JavaScript way'it.skip('5. JavaScript way'toit('5. JavaScript way'yarn test-only -- test/test341.jsImplementation Requirements
SQL-99 Features Involved
Dependencies
src/alasqlparser.jison)Acceptance Criteria
Test 4: JavaScript way
it.skip).length)[6, 6, 7]is returnedTest 5: JavaScript way
it.skip)[6, 6, 7]is returned for name lengthsTest Implementation Suggestions
Parser Changes Needed
In
src/alasqlparser.jison, add support for:Security Considerations
JavaScript expression evaluation should:
Notes
These tests are critical for AlaSQL's JavaScript integration capabilities. The ability to access JavaScript properties and methods within SQL provides powerful functionality for data manipulation and transformation.
</issue_description>
Comments on the Issue (you are@copilot in this section)
💬 We'd love your input! Share your thoughts on Copilot coding agent in our2 minute survey.