• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

typeorm / typeorm / 20153290793

12 Dec 2025 01:29AM UTC coverage: 80.807% (+0.04%) from 80.764%
20153290793

push

github

alumni
refactor(mysql)!: drop support for mysql package and default to mysql2 (#11766)

Co-authored-by: Lucian Mocanu <alumni@users.noreply.github.com>

26912 of 32666 branches covered (82.39%)

Branch coverage included in aggregate %.

13 of 15 new or added lines in 2 files covered. (86.67%)

694 existing lines in 23 files now uncovered.

91350 of 113685 relevant lines covered (80.35%)

68942.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/query-runner/QueryRunner.ts
1
import { TableColumn } from "../schema-builder/table/TableColumn"
×
2
import { Table } from "../schema-builder/table/Table"
×
3
import { TableForeignKey } from "../schema-builder/table/TableForeignKey"
×
4
import { TableIndex } from "../schema-builder/table/TableIndex"
×
5
import { DataSource } from "../data-source/DataSource"
×
6
import { ReadStream } from "../platform/PlatformTools"
×
7
import { EntityManager } from "../entity-manager/EntityManager"
×
8
import { ObjectLiteral } from "../common/ObjectLiteral"
×
9
import { SqlInMemory } from "../driver/SqlInMemory"
×
10
import { TableUnique } from "../schema-builder/table/TableUnique"
×
11
import { View } from "../schema-builder/view/View"
×
12
import { Broadcaster } from "../subscriber/Broadcaster"
×
13
import { TableCheck } from "../schema-builder/table/TableCheck"
×
14
import { IsolationLevel } from "../driver/types/IsolationLevel"
×
15
import { TableExclusion } from "../schema-builder/table/TableExclusion"
×
16
import { QueryResult } from "./QueryResult"
×
17
import { ReplicationMode } from "../driver/types/ReplicationMode"
×
18

×
19
/**
×
20
 * Runs queries on a single database connection.
×
21
 */
×
22
export interface QueryRunner extends AsyncDisposable {
×
23
    /**
×
24
     * Connection used by this query runner.
×
25
     */
×
26
    readonly connection: DataSource
×
27

×
28
    /**
×
29
     * Broadcaster used on this query runner to broadcast entity events.
×
30
     */
×
31
    readonly broadcaster: Broadcaster
×
32

×
33
    /**
×
34
     * Entity manager working only with this query runner.
×
35
     */
×
36
    readonly manager: EntityManager
×
37

×
38
    /**
×
39
     * Indicates if connection for this query runner is released.
×
40
     * Once its released, query runner cannot run queries anymore.
×
41
     */
×
42
    readonly isReleased: boolean
×
43

×
44
    /**
×
45
     * Indicates if transaction is in progress.
×
46
     */
×
47
    readonly isTransactionActive: boolean
×
48

×
49
    /**
×
50
     * Stores temporarily user data.
×
51
     * Useful for sharing data with subscribers.
×
52
     */
×
53
    data: ObjectLiteral
×
54

×
55
    /**
×
56
     * All synchronized tables in the database.
×
57
     *
×
58
     * @deprecated Call `getTables()`
×
59
     */
×
60
    loadedTables: Table[]
×
61

×
62
    /**
×
63
     * All synchronized views in the database.
×
64
     *
×
65
     * @deprecated Call `getViews()`
×
66
     */
×
67
    loadedViews: View[]
×
68

×
69
    /**
×
70
     * Creates/uses database connection from the connection pool to perform further operations.
×
71
     * Returns obtained database connection.
×
72
     */
×
73
    connect(): Promise<any>
×
74

×
75
    /**
×
76
     * Called before migrations are run.
×
77
     */
×
78
    beforeMigration(): Promise<void>
×
79

×
80
    /**
×
81
     * Called after migrations are run.
×
82
     */
×
83
    afterMigration(): Promise<void>
×
84

×
85
    /**
×
86
     * Releases used database connection.
×
87
     * You cannot use query runner methods after connection is released.
×
88
     */
×
89
    release(): Promise<void>
×
90

×
91
    [Symbol.asyncDispose](): Promise<void>
×
92

×
93
    /**
×
94
     * Removes all tables from the currently connected database.
×
95
     * Be careful with using this method and avoid using it in production or migrations
×
96
     * (because it can clear all your database).
×
97
     */
×
98
    clearDatabase(database?: string): Promise<void>
×
99

×
100
    /**
×
101
     * Starts transaction.
×
102
     */
×
103
    startTransaction(isolationLevel?: IsolationLevel): Promise<void>
×
104

×
105
    /**
×
106
     * Commits transaction.
×
107
     * Error will be thrown if transaction was not started.
×
108
     */
×
109
    commitTransaction(): Promise<void>
×
110

×
111
    /**
×
112
     * Rollbacks transaction.
×
113
     * Error will be thrown if transaction was not started.
×
114
     */
×
115
    rollbackTransaction(): Promise<void>
×
116

×
117
    /**
×
118
     * Executes a given SQL query and returns raw database results.
×
119
     */
×
120
    query(
×
121
        query: string,
×
122
        parameters: any[] | undefined,
×
123
        useStructuredResult: true,
×
124
    ): Promise<QueryResult>
×
125

×
126
    /**
×
127
     * Executes a given SQL query and returns raw database results.
×
128
     */
×
129
    query(query: string, parameters?: any[]): Promise<any>
×
130

×
131
    /**
×
132
     * Tagged template function that executes raw SQL query and returns raw database results.
×
133
     * Template expressions are automatically transformed into database parameters.
×
134
     * Raw query execution is supported only by relational databases (MongoDB is not supported).
×
135
     * Note: Don't call this as a regular function, it is meant to be used with backticks to tag a template literal.
×
136
     * Example: queryRunner.sql`SELECT * FROM table_name WHERE id = ${id}`
×
137
     */
×
138
    sql<T = any>(
×
139
        strings: TemplateStringsArray,
×
140
        ...values: unknown[]
×
141
    ): Promise<T>
×
142

×
143
    /**
×
144
     * Returns raw data stream.
×
145
     */
×
146
    stream(
×
147
        query: string,
×
148
        parameters?: any[],
×
149
        onEnd?: Function,
×
150
        onError?: Function,
×
151
    ): Promise<ReadStream>
×
152

×
153
    /**
×
154
     * Returns all available database names including system databases.
×
155
     */
×
156
    getDatabases(): Promise<string[]>
×
157

×
158
    /**
×
159
     * Returns all available schema names including system schemas.
×
160
     * If database parameter specified, returns schemas of that database.
×
161
     * Useful for SQLServer and Postgres only.
×
162
     */
×
163
    getSchemas(database?: string): Promise<string[]>
×
164

×
165
    /**
×
166
     * Loads a table by a given name from the database.
×
167
     */
×
168
    getTable(tablePath: string): Promise<Table | undefined>
×
169

×
170
    /**
×
171
     * Loads all tables from the database and returns them.
×
172
     */
×
173
    getTables(tablePaths?: string[]): Promise<Table[]>
×
174

×
175
    /**
×
176
     * Loads a view by a given name from the database.
×
177
     */
×
178
    getView(viewPath: string): Promise<View | undefined>
×
179

×
180
    /**
×
181
     * Loads all views from the database and returns them.
×
182
     */
×
183
    getViews(viewPaths?: string[]): Promise<View[]>
×
184

×
185
    /**
×
186
     * Returns replication mode (ex: `master` or `slave`).
×
187
     */
×
188
    getReplicationMode(): ReplicationMode
×
189

×
190
    /**
×
191
     * Checks if a database with the given name exist.
×
192
     */
×
193
    hasDatabase(database: string): Promise<boolean>
×
194

×
195
    /**
×
196
     * Loads currently using database
×
197
     */
×
198
    getCurrentDatabase(): Promise<string | undefined>
×
199

×
200
    /**
×
201
     * Checks if a schema with the given name exist.
×
202
     */
×
203
    hasSchema(schema: string): Promise<boolean>
×
204

×
205
    /**
×
206
     * Loads currently using database schema
×
207
     */
×
208
    getCurrentSchema(): Promise<string | undefined>
×
209

×
210
    /**
×
211
     * Checks if a table with the given name exist.
×
212
     */
×
213
    hasTable(table: Table | string): Promise<boolean>
×
214

×
215
    /**
×
216
     * Checks if a column exist in the table.
×
217
     */
×
218
    hasColumn(table: Table | string, columnName: string): Promise<boolean>
×
219

×
220
    /**
×
221
     * Creates a new database.
×
222
     */
×
223
    createDatabase(database: string, ifNotExist?: boolean): Promise<void>
×
224

×
225
    /**
×
226
     * Drops database.
×
227
     */
×
228
    dropDatabase(database: string, ifExist?: boolean): Promise<void>
×
229

×
230
    /**
×
231
     * Creates a new table schema.
×
232
     */
×
233
    createSchema(schemaPath: string, ifNotExist?: boolean): Promise<void>
×
234

×
235
    /**
×
236
     * Drops table schema.
×
237
     * For SqlServer can accept schema path (e.g. 'dbName.schemaName') as parameter.
×
238
     * If schema path passed, it will drop schema in specified database.
×
239
     */
×
240
    dropSchema(
×
241
        schemaPath: string,
×
242
        ifExist?: boolean,
×
243
        isCascade?: boolean,
×
244
    ): Promise<void>
×
245

×
246
    /**
×
247
     * Creates a new table.
×
248
     */
×
249
    createTable(
×
250
        table: Table,
×
251
        ifNotExist?: boolean,
×
252
        createForeignKeys?: boolean,
×
253
        createIndices?: boolean,
×
254
    ): Promise<void>
×
255

×
256
    /**
×
257
     * Drops a table.
×
258
     */
×
259
    dropTable(
×
260
        table: Table | string,
×
261
        ifExist?: boolean,
×
262
        dropForeignKeys?: boolean,
×
263
        dropIndices?: boolean,
×
264
    ): Promise<void>
×
265

×
266
    /**
×
267
     * Creates a new view.
×
268
     */
×
269
    createView(
×
270
        view: View,
×
271
        syncWithMetadata?: boolean,
×
272
        oldView?: View,
×
273
    ): Promise<void>
×
274

×
275
    /**
×
276
     * Drops a view.
×
277
     */
×
278
    dropView(view: View | string): Promise<void>
×
279

×
280
    /**
×
281
     * Renames a table.
×
282
     */
×
283
    renameTable(
×
284
        oldTableOrName: Table | string,
×
285
        newTableName: string,
×
286
    ): Promise<void>
×
287

×
288
    /**
×
289
     * Change table comment. Only supports MySQL and MariaDB
×
290
     */
×
291
    changeTableComment(
×
292
        tableOrName: Table | string,
×
293
        comment?: string,
×
294
    ): Promise<void>
×
295

×
296
    /**
×
297
     * Adds a new column.
×
298
     */
×
299
    addColumn(table: Table | string, column: TableColumn): Promise<void>
×
300

×
301
    /**
×
302
     * Adds new columns.
×
303
     */
×
304
    addColumns(table: Table | string, columns: TableColumn[]): Promise<void>
×
305

×
306
    /**
×
307
     * Renames a column.
×
308
     */
×
309
    renameColumn(
×
310
        table: Table | string,
×
311
        oldColumnOrName: TableColumn | string,
×
312
        newColumnOrName: TableColumn | string,
×
313
    ): Promise<void>
×
314

×
315
    /**
×
316
     * Changes a column in the table.
×
317
     */
×
318
    changeColumn(
×
319
        table: Table | string,
×
320
        oldColumn: TableColumn | string,
×
321
        newColumn: TableColumn,
×
322
    ): Promise<void>
×
323

×
324
    /**
×
325
     * Changes columns in the table.
×
326
     */
×
327
    changeColumns(
×
328
        table: Table | string,
×
329
        changedColumns: { oldColumn: TableColumn; newColumn: TableColumn }[],
×
330
    ): Promise<void>
×
331

×
332
    /**
×
333
     * Drops a column in the table.
×
334
     */
×
335
    dropColumn(
×
336
        table: Table | string,
×
337
        column: TableColumn | string,
×
338
    ): Promise<void>
×
339

×
340
    /**
×
341
     * Drops columns in the table.
×
342
     */
×
343
    dropColumns(
×
344
        table: Table | string,
×
345
        columns: TableColumn[] | string[],
×
346
    ): Promise<void>
×
347

×
348
    /**
×
349
     * Creates a new primary key.
×
350
     */
×
351
    createPrimaryKey(
×
352
        table: Table | string,
×
353
        columnNames: string[],
×
354
        constraintName?: string,
×
355
    ): Promise<void>
×
356

×
357
    /**
×
358
     * Updates composite primary keys.
×
359
     */
×
360
    updatePrimaryKeys(
×
361
        table: Table | string,
×
362
        columns: TableColumn[],
×
363
    ): Promise<void>
×
364

×
365
    /**
×
366
     * Drops a primary key.
×
367
     */
×
368
    dropPrimaryKey(
×
369
        table: Table | string,
×
370
        constraintName?: string,
×
371
    ): Promise<void>
×
372

×
373
    /**
×
374
     * Creates a new unique constraint.
×
375
     */
×
376
    createUniqueConstraint(
×
377
        table: Table | string,
×
378
        uniqueConstraint: TableUnique,
×
379
    ): Promise<void>
×
380

×
381
    /**
×
382
     * Creates new unique constraints.
×
383
     */
×
384
    createUniqueConstraints(
×
385
        table: Table | string,
×
386
        uniqueConstraints: TableUnique[],
×
387
    ): Promise<void>
×
388

×
389
    /**
×
390
     * Drops a unique constraint.
×
391
     */
×
392
    dropUniqueConstraint(
×
393
        table: Table | string,
×
394
        uniqueOrName: TableUnique | string,
×
395
    ): Promise<void>
×
396

×
397
    /**
×
398
     * Drops unique constraints.
×
399
     */
×
400
    dropUniqueConstraints(
×
401
        table: Table | string,
×
402
        uniqueConstraints: TableUnique[],
×
403
    ): Promise<void>
×
404

×
405
    /**
×
406
     * Creates a new check constraint.
×
407
     */
×
408
    createCheckConstraint(
×
409
        table: Table | string,
×
410
        checkConstraint: TableCheck,
×
411
    ): Promise<void>
×
412

×
413
    /**
×
414
     * Creates new check constraints.
×
415
     */
×
416
    createCheckConstraints(
×
417
        table: Table | string,
×
418
        checkConstraints: TableCheck[],
×
419
    ): Promise<void>
×
420

×
421
    /**
×
422
     * Drops a check constraint.
×
423
     */
×
424
    dropCheckConstraint(
×
425
        table: Table | string,
×
426
        checkOrName: TableCheck | string,
×
427
    ): Promise<void>
×
428

×
429
    /**
×
430
     * Drops check constraints.
×
431
     */
×
432
    dropCheckConstraints(
×
433
        table: Table | string,
×
434
        checkConstraints: TableCheck[],
×
435
    ): Promise<void>
×
436

×
437
    /**
×
438
     * Creates a new exclusion constraint.
×
439
     */
×
440
    createExclusionConstraint(
×
441
        table: Table | string,
×
442
        exclusionConstraint: TableExclusion,
×
443
    ): Promise<void>
×
444

×
445
    /**
×
446
     * Creates new exclusion constraints.
×
447
     */
×
448
    createExclusionConstraints(
×
449
        table: Table | string,
×
450
        exclusionConstraints: TableExclusion[],
×
451
    ): Promise<void>
×
452

×
453
    /**
×
454
     * Drops a exclusion constraint.
×
455
     */
×
456
    dropExclusionConstraint(
×
457
        table: Table | string,
×
458
        exclusionOrName: TableExclusion | string,
×
459
    ): Promise<void>
×
460

×
461
    /**
×
462
     * Drops exclusion constraints.
×
463
     */
×
464
    dropExclusionConstraints(
×
465
        table: Table | string,
×
466
        exclusionConstraints: TableExclusion[],
×
467
    ): Promise<void>
×
468

×
469
    /**
×
470
     * Creates a new foreign key.
×
471
     */
×
472
    createForeignKey(
×
473
        table: Table | string,
×
474
        foreignKey: TableForeignKey,
×
475
    ): Promise<void>
×
476

×
477
    /**
×
478
     * Creates new foreign keys.
×
479
     */
×
480
    createForeignKeys(
×
481
        table: Table | string,
×
482
        foreignKeys: TableForeignKey[],
×
483
    ): Promise<void>
×
484

×
485
    /**
×
486
     * Drops a foreign key.
×
487
     */
×
488
    dropForeignKey(
×
489
        table: Table | string,
×
490
        foreignKeyOrName: TableForeignKey | string,
×
491
    ): Promise<void>
×
492

×
493
    /**
×
494
     * Drops foreign keys.
×
495
     */
×
496
    dropForeignKeys(
×
497
        table: Table | string,
×
498
        foreignKeys: TableForeignKey[],
×
499
    ): Promise<void>
×
500

×
501
    /**
×
502
     * Creates a new index.
×
503
     */
×
504
    createIndex(table: Table | string, index: TableIndex): Promise<void>
×
505

×
506
    /**
×
507
     * Creates new indices.
×
508
     */
×
509
    createIndices(table: Table | string, indices: TableIndex[]): Promise<void>
×
510

×
511
    /**
×
512
     * Drops an index.
×
513
     */
×
514
    dropIndex(table: Table | string, index: TableIndex | string): Promise<void>
×
515

×
516
    /**
×
517
     * Drops indices.
×
518
     */
×
519
    dropIndices(table: Table | string, indices: TableIndex[]): Promise<void>
×
520

×
521
    /**
×
522
     * Clears all table contents.
×
523
     * Note: this operation uses SQL's TRUNCATE query which cannot be reverted in transactions.
×
524
     */
×
525
    clearTable(tableName: string): Promise<void>
×
526

×
527
    /**
×
528
     * Enables special query runner mode in which sql queries won't be executed,
×
529
     * instead they will be memorized into a special variable inside query runner.
×
530
     * You can get memorized sql using getMemorySql() method.
×
531
     */
×
532
    enableSqlMemory(): void
×
533

×
534
    /**
×
535
     * Disables special query runner mode in which sql queries won't be executed
×
536
     * started by calling enableSqlMemory() method.
×
537
     *
×
538
     * Previously memorized sql will be flushed.
×
539
     */
×
540
    disableSqlMemory(): void
×
541

×
542
    /**
×
543
     * Flushes all memorized sqls.
×
544
     */
×
545
    clearSqlMemory(): void
×
546

×
547
    /**
×
548
     * Gets sql stored in the memory. Parameters in the sql are already replaced.
×
549
     */
×
550
    getMemorySql(): SqlInMemory
×
551

×
552
    /**
×
553
     * Executes up sql queries.
×
554
     */
×
555
    executeMemoryUpSql(): Promise<void>
×
556

×
557
    /**
×
558
     * Executes down sql queries.
×
559
     */
×
UNCOV
560
    executeMemoryDownSql(): Promise<void>
×
UNCOV
561
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc