From 674501fb4bfffda80192e26d28238d278d80d1af Mon Sep 17 00:00:00 2001 From: shiyuhang <1136742008@qq.com> Date: Fri, 5 Jan 2024 16:54:01 +0800 Subject: [PATCH] fix config not work --- integration-test/basic.test.ts | 35 ++++++++++++++++++++++++++++++++++ src/index.ts | 7 ++----- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/integration-test/basic.test.ts b/integration-test/basic.test.ts index 053c7d4..cc8ec93 100644 --- a/integration-test/basic.test.ts +++ b/integration-test/basic.test.ts @@ -65,6 +65,41 @@ describe('basic', () => { expect(JSON.stringify(result2)).toEqual(JSON.stringify(except2)) }) + test('arrayMode with config and option', async () => { + const con = connect({url: databaseURL, database: database, fetch, arrayMode: true}) + const result1 = await con.execute(`select * from ${table} where emp_no=0`,null, {arrayMode: false}) + const result2 = await con.execute(`select * from ${table} where emp_no=0`) + const except1: Row[] = [ { emp_no: 0, first_name: 'base', last_name: 'base' } ] + const except2: Row[] = [[0, 'base', 'base']] + expect(JSON.stringify(result1)).toEqual(JSON.stringify(except1)) + expect(JSON.stringify(result2)).toEqual(JSON.stringify(except2)) + }) + + test('fullResult with config and option', async () => { + const con = connect({url: databaseURL, database: database, fetch, fullResult: true}) + const result1 = await con.execute(`select * from ${table} where emp_no=0`,null, {fullResult: false}) + const result2 = await con.execute(`select * from ${table} where emp_no=0`) + const except1: Row[] = [ { emp_no: 0, first_name: 'base', last_name: 'base' } ] + const except2: FullResult = { + statement: `select * from ${table} where emp_no=0`, + types:{ + emp_no: 'INT', + first_name: 'VARCHAR', + last_name: 'VARCHAR' + }, + rows: [{ + emp_no: 0, + first_name: 'base', + last_name: 'base' + }], + rowsAffected: 0, + lastInsertId: null, + rowCount: 1 + } + expect(JSON.stringify(result1)).toEqual(JSON.stringify(except1)) + expect(JSON.stringify(result2)).toEqual(JSON.stringify(except2)) + }) + test('query with escape', async () => { const con = connect({url: databaseURL, database: database, fetch}) await con.execute(`delete from ${table} where emp_no = 1 or emp_no = 2`) diff --git a/src/index.ts b/src/index.ts index 6c9f912..b7631d6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -33,10 +33,7 @@ interface QueryExecuteResponse { lastInsertID: number | null } -const defaultExecuteOptions: ExecuteOptions = { - arrayMode: false, - fullResult: false -} +const defaultExecuteOptions: ExecuteOptions = {} export class Tx { private conn: Connection @@ -119,7 +116,7 @@ export class Connection { } const arrayMode = options.arrayMode ?? this.config.arrayMode ?? false - const fullResult = options.fullResult ?? this.config.arrayMode ?? false + const fullResult = options.fullResult ?? this.config.fullResult ?? false const decoders = { ...this.config.decoders, ...options.decoders } const fields = resp?.types ?? []