Skip to content

Commit

Permalink
set session in header (#12)
Browse files Browse the repository at this point in the history
* set session in header

* set session in header

* increase timeout
  • Loading branch information
shiyuhang0 authored Sep 12, 2023
1 parent f8b39eb commit c390f24
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion integration-test/type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ beforeAll(async () => {
await con.execute(`DROP DATABASE IF EXISTS ${database}`)
await con.execute(`CREATE DATABASE ${database}`)
await con.execute(multiDataTable)
},10000);
},20000);

describe('types', () => {

Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Res = {
ok: boolean
status: number
statusText: string
headers: any
json(): Promise<any>
text(): Promise<string>
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class Connection {
const resp = await postQuery<QueryExecuteResponse>(this.config, body, this.session ?? '')

this.session = resp?.session ?? null
if (this.session === null) {
if (this.session === null || this.session === '') {
throw new DatabaseError('empty session, please try again', 500, null)
}

Expand Down
5 changes: 4 additions & 1 deletion src/serverless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export async function postQuery<T>(config: Config, body, session = ''): Promise<
})

if (response.ok) {
return await response.json()
const resp = await response.json()
const session = response.headers.get('TiDB-Session')
resp.session = session ?? ''
return resp
} else {
let error
try {
Expand Down

0 comments on commit c390f24

Please sign in to comment.