tursodatabase / tursodatabase/libsql-client-ts
`select 1 'adsf'` yields error "Cannot redefine property: 1"
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 576
- Forks
- 69
- PR merge metrics
- No merged PRs in 30d
Description
Working against current main.
const rs = await client.execute("select 1, 'asdf'")
TypeError: Cannot redefine property: 1
at Function.defineProperty (<anonymous>)
at rowFromProto (/Users/doug/work/chiselstrike/codingdoug/libsql-client-ts/node_modules/@libsql/hrana-client/lib-cjs/result.js:45:16)
at /Users/doug/work/chiselstrike/codingdoug/libsql-client-ts/node_modules/@libsql/hrana-client/lib-cjs/result.js:17:41
at Array.map (<anonymous>)
at rowsResultFromProto (/Users/doug/work/chiselstrike/codingdoug/libsql-client-ts/node_modules/@libsql/hrana-client/lib-cjs/result.js:17:30)
at /Users/doug/work/chiselstrike/codingdoug/libsql-client-ts/node_modules/@libsql/hrana-client/lib-cjs/stream.js:33:48
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async HttpClient.execute (/Users/doug/work/chiselstrike/codingdoug/libsql-client-ts/lib-cjs/http.js:81:55)
This does not happen with:
select 1select 0.1select 0select 2, 'asdf'select 'asdf'select 'asdf', 1
It does happen with:
select 99, 2, 'asdf'
This SQL yields a result set that contains a single row value which contains an empty object (instead of {'0': 'asdf'}:
select 'asdf' as '0'
The problem I believe is this: since ResultSet rows are populated and can be used as both an array and an object (using both integer column index and string column names on the object), there can be a collision when the name of a column happens to match one of the used integer indexes for array usage.
I don't see that there is a fix or workaround as long as rows are populated this way.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the listed queries, then inspect rowFromProto in node_modules/@libsql/hrana-client/lib-cjs/result.js and the related result conversion path in stream.js. Check how array indexes and column names are defined on each row, including the '0' alias case. Done means the failing queries no longer throw and returned row values remain accessible as intended.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- sqlite, typescript
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100