Open penberg opened 1 year ago
I looked a little deeper into the query and ran the rowFromSql
method inside a TypeScript Playground with target es2022
on v5.2.2
and its returning as an object.
As pointed out previously by @adoublef , the collision described in #92 can also occur on columns named length
.
I think the ResultSet
structure should change as a result of these collision potentials to something else. Perhaps rows
can be a list of [column, value]
tuples which do not have the same issue of collision and are also compatible with Object.fromEntries
should the user wish to parse a row into an object themselves.
As the current approach tries to allow both column index indexing and column name indexing to retrieve values , this can still be done with minimal JS from the user:
Column index indexing: row[i][1]
Column name indexing Object.fromEntries(row)[name]
I have an example of the code using Symbol.Iterator
I was pondering over this and feel that this could mean less of a change to the existing expectation of the client package. The row object can then still technically be used as either an object or an array via a spread operator.
The only con is that I'm unsure the minimum target for Node and Typescript this library is supposed to be. And unsure if there may be compatibility issues with earlier versions. I have only tested on TS v3.3.3
to v5.2.2
so outside that range may be unexpected behaviour using iterators
The
execute()
method returnsRow
objects that can be accessed either as an array or an object, which confusesdeepEquals()
in tests, for example.