Skip to content
Open
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
55 changes: 55 additions & 0 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,61 @@ describe('execute', () => {
assert.deepStrictEqual(got, want)
})

test('returns column metadata for wide queries with no rows', async () => {
const fields = Array.from({ length: 2048 }, (_, i) => ({ name: `column_${i}`, type: 'VARCHAR' }))
const types: Record<string, string> = {}
for (const field of fields) {
types[field.name] = field.type
}

mockPool.intercept({ path: EXECUTE_PATH, method: 'POST' }).reply(200, {
result: { fields, rows: [] }
})

const got = await connect(config).execute('SELECT wide columns')

assert.deepStrictEqual(
got.headers,
fields.map((field) => field.name)
)
assert.deepStrictEqual(got.types, types)
assert.deepStrictEqual(got.fields, fields)
assert.deepStrictEqual(got.rows, [])
})

test('preserves duplicate and special column names in type metadata', async () => {
mockPool.intercept({ path: EXECUTE_PATH, method: 'POST' }).reply(200, {
result: {
fields: [
{ name: '__proto__', type: 'VARCHAR' },
{ name: 'constructor', type: 'INT32' },
{ name: 'toString', type: 'VARCHAR' },
{ name: 'duplicate', type: 'INT32' },
{ name: 'duplicate', type: 'VARCHAR' },
{ name: '__proto__' }
],
rows: []
}
})

const got = await connect(config).execute('SELECT duplicate and special columns')

assert.deepStrictEqual(got.headers, ['__proto__', 'constructor', 'toString', 'duplicate', 'duplicate', '__proto__'])
assert.deepStrictEqual(got.types, {
['__proto__']: 'NULL',
constructor: 'INT32',
toString: 'VARCHAR',
duplicate: 'VARCHAR'
})
assert.strictEqual(Object.getPrototypeOf(got.types), Object.prototype)
assert.deepStrictEqual(Object.getOwnPropertyDescriptor(got.types, '__proto__'), {
value: 'NULL',
enumerable: true,
writable: true,
configurable: true
})
})

test('it properly returns an executed query for a DDL statement', async () => {
const mockResponse = {
session: mockSession,
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,7 @@ export class Connection {
const rows = result ? parse<T>(result, castFn, options.as || 'object') : []
const headers = fields.map((f) => f.name)

const typeByName = (acc: Types, { name, type }: Field) => ({ ...acc, [name]: type })
const types = fields.reduce<Types>(typeByName, {})
const types: Types = Object.fromEntries(fields.map(({ name, type }) => [name, type]))
const timingSeconds = timing ?? 0

return {
Expand Down