Conversation
Result rows reserve a non-enumerable "length" property so that a row can be indexed like an array. When a result column is named "length" (e.g. SELECT COUNT(*) AS "length"), the column value was swallowed by that property and rows appeared empty. Define the array-like "length" only when no column claims the name, so the column value takes precedence. For the hrana-based clients, rows built by @libsql/hrana-client have a non-configurable "length" property, so rebuild them in resultSetFromHrana when a "length" column is present. ResultSet.toJSON() also iterated rows via row.length, which is no longer reliable; iterate the real column count instead. Fixes tursodatabase#234
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A query aliasing a column as
lengthreturns rows where that column is missing.rowFromSqlinpackages/libsql-client-wasm/src/wasm.tsdefines a non-enumerablelengthon the row object first,so a column genuinely named
lengthcannot be defined over it and the value is lost.The row's own
lengthexists so a row behaves array-like, which is worth keeping, but a real columnhas the better claim on the name: the caller asked for it and there is no other way to read it, while
the array-like length is a convenience the column count already provides.
This moves the
lengthdefinition after the column loop and only defines it when no column claimedthe name. Rows without such a column are unchanged.
Fixes #234