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
23 changes: 9 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,15 @@ export class Connection {
}
}

function parseRow(fields: QueryResultField[], rawRow: QueryResultRow): any {
function parseRow(fields: QueryResultField[], rawRow: QueryResultRow): Row {
const row = decodeRow(rawRow)
const rv = {}

for (let i = 0; i < fields.length; i++) {
const field = fields[i]
const column = row[i]
const parsedValue = parseColumn(field.type, column)

rv[field.name] = parsedValue
}

return rv
return fields.reduce((acc, field, ix) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya know, this is way simpler and I vibe with this heavy.

acc[field.name] = parseColumn(field.type, row[ix])
return acc
}, {} as Row)
}

function parse(result: QueryResult): any[] {
function parse(result: QueryResult): Row[] {
const fields = result.fields
const rows = result.rows ?? []
return rows.map((row) => parseRow(fields, row))
Expand Down Expand Up @@ -208,9 +201,11 @@ function parseColumn(type: string, value: string) {
}
}

type Row = Record<string, unknown>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noice.


export interface ExecutedQuery {
headers?: string[]
rows?: any[]
rows?: Row[]
size?: number
statement?: string
rawError?: Error
Expand Down