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

Fix config not work #41

Merged
merged 1 commit into from
Jan 5, 2024
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
35 changes: 35 additions & 0 deletions integration-test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
7 changes: 2 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ?? []
Expand Down