tursodatabase / libsql-client-ts

TypeScript/JavaScript client API for libSQL
https://docs.turso.tech/sdk/ts/quickstart
MIT License
226 stars 32 forks source link

`select 1 'adsf'` yields error "Cannot redefine property: 1" #92

Open CodingDoug opened 1 year ago

CodingDoug commented 1 year ago

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:

It does happen with:

This SQL yields a result set that contains a single row value which contains an empty object (instead of {'0': 'asdf'}:

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.