Skip to content

Commit 4a30094

Browse files
committed
...
1 parent 1db3b58 commit 4a30094

File tree

2 files changed

+3
-32
lines changed

2 files changed

+3
-32
lines changed

src/dialect/mysql/mysql-dialect-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export interface MysqlPoolConnection {
5353
callback: (error: unknown, result: MysqlQueryResult) => void,
5454
): void
5555
release(): void
56+
threadId: number
5657
}
5758

5859
export interface MysqlStreamOptions {

src/dialect/mysql/mysql-driver.ts

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ function isOkPacket(obj: unknown): obj is MysqlOkPacket {
166166

167167
class MysqlConnection implements DatabaseConnection {
168168
readonly #rawConnection: MysqlPoolConnection
169-
#cid: unknown
170169

171170
constructor(rawConnection: MysqlPoolConnection) {
172171
this.#rawConnection = rawConnection
@@ -175,12 +174,6 @@ class MysqlConnection implements DatabaseConnection {
175174
async cancelQuery(
176175
controlConnectionProvider: ControlConnectionProvider,
177176
): Promise<void> {
178-
if (!this.#cid) {
179-
return logOnce(
180-
'kysely:warning: cannot cancel query because the connection has not been made cancelable.',
181-
)
182-
}
183-
184177
try {
185178
// this removes the connection from the pool.
186179
// this is done to avoid picking it up after the `kill` command next, which
@@ -196,20 +189,13 @@ class MysqlConnection implements DatabaseConnection {
196189
// guarantee that the query is killed immediately. we saw that in tests,
197190
// the query can still run for a while after - including registering writes.
198191
await controlConnection.executeQuery(
199-
CompiledQuery.raw('kill connection ?', [this.#cid]),
192+
CompiledQuery.raw('kill connection ?', [this.#rawConnection.threadId]),
200193
)
201194
})
202195
}
203196

204-
async executeQuery<O>(
205-
compiledQuery: CompiledQuery,
206-
options?: QueryOptions,
207-
): Promise<QueryResult<O>> {
197+
async executeQuery<O>(compiledQuery: CompiledQuery): Promise<QueryResult<O>> {
208198
try {
209-
if (options?.cancelable) {
210-
await this.#setupCancelability()
211-
}
212-
213199
const result = await this.#executeQuery(compiledQuery)
214200

215201
if (!isOkPacket(result)) {
@@ -247,10 +233,6 @@ class MysqlConnection implements DatabaseConnection {
247233
_chunkSize: number,
248234
options?: QueryOptions,
249235
): AsyncIterableIterator<QueryResult<O>> {
250-
if (options?.cancelable) {
251-
await this.#setupCancelability()
252-
}
253-
254236
const stream = this.#rawConnection
255237
.query(compiledQuery.sql, compiledQuery.parameters)
256238
.stream<O>({ objectMode: true })
@@ -295,16 +277,4 @@ class MysqlConnection implements DatabaseConnection {
295277
)
296278
})
297279
}
298-
299-
async #setupCancelability(): Promise<void> {
300-
if (this.#cid) {
301-
return
302-
}
303-
304-
const results = await this.#executeQuery(
305-
CompiledQuery.raw('select connection_id() as cid', []),
306-
)
307-
308-
this.#cid = (results as any[])[0]?.cid
309-
}
310280
}

0 commit comments

Comments
 (0)