Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adapter-libsql: fix failing apply_number_ops_for_int test #4296

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class UnexpectedTypeError extends Error {
}
}

export function mapRow(row: Row): unknown[] {
export function mapRow(row: Row, columnTypes: ColumnType[]): unknown[] {
// `Row` doesn't have map, so we copy the array once and modify it in-place
// to avoid allocating and copying twice if we used `Array.from(row).map(...)`.
const result: unknown[] = Array.from(row)
Expand All @@ -145,6 +145,16 @@ export function mapRow(row: Row): unknown[] {
if (isArrayBuffer(value)) {
result[i] = Array.from(new Uint8Array(value))
}

// If an integer is required and the current number isn't one,
// discard the fractional part.
if (
typeof value === 'number' &&
(columnTypes[i] === ColumnTypeEnum.Int32 || columnTypes[i] === ColumnTypeEnum.Int64) &&
!Number.isInteger(value)
) {
result[i] = Math.trunc(value)
}
}

return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class LibSqlQueryable<ClientT extends StdClient | TransactionClient> implements
const resultSet: ResultSet = {
columnNames: columns,
columnTypes,
rows: rows.map(mapRow),
rows: rows.map((row) => mapRow(row, columnTypes)),
}

return ok(resultSet)
Expand Down