Skip to content
Merged
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
31 changes: 12 additions & 19 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,29 +159,22 @@ function parse(result: QueryResult): Row[] {
return rows.map((row) => parseRow(fields, row))
}

function decodeRow(row: QueryResultRow) {
function decodeRow(row: QueryResultRow): Array<string | null> {
const values = atob(row.values)
const rv = []
let offset = 0
for (let i = 0; i < row.lengths.length; i++) {
const ll = parseInt(row.lengths[i], 10)
// If the length is less than zero, it indicates a null value, so we should
// just call it an empty string and move on.
if (ll < 0) {
rv.push('')
continue
}

rv.push(values.substring(offset, offset + ll))
offset += ll
}
return rv
return row.lengths.map((size) => {
const width = parseInt(size, 10)
// Negative length indicates a null value.
if (width < 0) return null
const splice = values.substring(offset, offset + width)
offset += width
return splice
})
}

function parseColumn(type: string, value: string) {
// For empty strings, just return back a blank string.
if (value === '' || null) {
return ''
function parseColumn(type: string, value: string | null): number | string | null {
if (value === '' || value == null) {
return value
}

switch (type) {
Expand Down