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

typeorm / typeorm / 15219332477

23 May 2025 09:13PM UTC coverage: 17.216% (-59.1%) from 76.346%
15219332477

Pull #11332

github

naorpeled
cr comments - move if block
Pull Request #11332: feat: add new undefined and null behavior flags

1603 of 12759 branches covered (12.56%)

Branch coverage included in aggregate %.

0 of 31 new or added lines in 3 files covered. (0.0%)

14132 existing lines in 166 files now uncovered.

4731 of 24033 relevant lines covered (19.69%)

60.22 hits per line

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

3.24
/src/query-runner/BaseQueryRunner.ts
1
import { PostgresConnectionOptions } from "../driver/postgres/PostgresConnectionOptions"
2
import { Query } from "../driver/Query"
1✔
3
import { SqlInMemory } from "../driver/SqlInMemory"
1✔
4
import { SqlServerConnectionOptions } from "../driver/sqlserver/SqlServerConnectionOptions"
5
import { TableIndex } from "../schema-builder/table/TableIndex"
6
import { View } from "../schema-builder/view/View"
7
import { DataSource } from "../data-source/DataSource"
8
import { Table } from "../schema-builder/table/Table"
9
import { EntityManager } from "../entity-manager/EntityManager"
10
import { TableColumn } from "../schema-builder/table/TableColumn"
11
import { Broadcaster } from "../subscriber/Broadcaster"
12
import { ReplicationMode } from "../driver/types/ReplicationMode"
13
import { TypeORMError } from "../error/TypeORMError"
1✔
14
import { EntityMetadata } from "../metadata/EntityMetadata"
15
import { TableForeignKey } from "../schema-builder/table/TableForeignKey"
16
import { OrmUtils } from "../util/OrmUtils"
1✔
17
import { MetadataTableType } from "../driver/types/MetadataTableType"
18
import { InstanceChecker } from "../util/InstanceChecker"
1✔
19
import { buildSqlTag } from "../util/SqlTagUtils"
1✔
20

21
export abstract class BaseQueryRunner {
1✔
22
    // -------------------------------------------------------------------------
23
    // Public Properties
24
    // -------------------------------------------------------------------------
25

26
    /**
27
     * Connection used by this query runner.
28
     */
29
    connection: DataSource
30

31
    /**
32
     * Entity manager working only with current query runner.
33
     */
34
    manager: EntityManager
35

36
    /**
37
     * Indicates if connection for this query runner is released.
38
     * Once its released, query runner cannot run queries anymore.
39
     */
UNCOV
40
    isReleased = false
×
41

42
    /**
43
     * Indicates if transaction is in progress.
44
     */
UNCOV
45
    isTransactionActive = false
×
46

47
    /**
48
     * Stores temporarily user data.
49
     * Useful for sharing data with subscribers.
50
     */
UNCOV
51
    data = {}
×
52

53
    /**
54
     * All synchronized tables in the database.
55
     */
UNCOV
56
    loadedTables: Table[] = []
×
57

58
    /**
59
     * All synchronized views in the database.
60
     */
UNCOV
61
    loadedViews: View[] = []
×
62

63
    /**
64
     * Broadcaster used on this query runner to broadcast entity events.
65
     */
66
    broadcaster: Broadcaster
67

68
    // -------------------------------------------------------------------------
69
    // Protected Properties
70
    // -------------------------------------------------------------------------
71

72
    /**
73
     * Real database connection from a connection pool used to perform queries.
74
     */
75
    protected databaseConnection: any
76

77
    /**
78
     * Indicates if special query runner mode in which sql queries won't be executed is enabled.
79
     */
UNCOV
80
    protected sqlMemoryMode: boolean = false
×
81

82
    /**
83
     * Sql-s stored if "sql in memory" mode is enabled.
84
     */
UNCOV
85
    protected sqlInMemory: SqlInMemory = new SqlInMemory()
×
86

87
    /**
88
     * Mode in which query runner executes.
89
     * Used for replication.
90
     * If replication is not setup its value is ignored.
91
     */
92
    protected mode: ReplicationMode
93

94
    /**
95
     * current depth of transaction.
96
     * for transactionDepth > 0 will use SAVEPOINT to start and commit/rollback transaction blocks
97
     */
UNCOV
98
    protected transactionDepth = 0
×
99

UNCOV
100
    private cachedTablePaths: Record<string, string> = {}
×
101

102
    // -------------------------------------------------------------------------
103
    // Public Abstract Methods
104
    // -------------------------------------------------------------------------
105

106
    /**
107
     * Executes a given SQL query.
108
     */
109
    abstract query(
110
        query: string,
111
        parameters?: any[],
112
        useStructuredResult?: boolean,
113
    ): Promise<any>
114

115
    /**
116
     * Tagged template function that executes raw SQL query and returns raw database results.
117
     * Template expressions are automatically transformed into database parameters.
118
     * Raw query execution is supported only by relational databases (MongoDB is not supported).
119
     * Note: Don't call this as a regular function, it is meant to be used with backticks to tag a template literal.
120
     * Example: queryRunner.sql`SELECT * FROM table_name WHERE id = ${id}`
121
     */
122
    async sql<T = any>(
123
        strings: TemplateStringsArray,
124
        ...values: unknown[]
125
    ): Promise<T> {
126
        const { query, parameters } = buildSqlTag({
×
127
            driver: this.connection.driver,
128
            strings: strings,
129
            expressions: values,
130
        })
131

132
        return await this.query(query, parameters)
×
133
    }
134

135
    // -------------------------------------------------------------------------
136
    // Protected Abstract Methods
137
    // -------------------------------------------------------------------------
138

139
    protected abstract loadTables(tablePaths?: string[]): Promise<Table[]>
140

141
    protected abstract loadViews(tablePaths?: string[]): Promise<View[]>
142

143
    // -------------------------------------------------------------------------
144
    // Public Methods
145
    // -------------------------------------------------------------------------
146

147
    /**
148
     * Called before migrations are run.
149
     */
150
    async beforeMigration(): Promise<void> {
151
        // Do nothing
152
    }
153

154
    /**
155
     * Called after migrations are run.
156
     */
157
    async afterMigration(): Promise<void> {
158
        // Do nothing
159
    }
160

161
    /**
162
     * Loads given table's data from the database.
163
     */
164
    async getTable(tablePath: string): Promise<Table | undefined> {
UNCOV
165
        this.loadedTables = await this.loadTables([tablePath])
×
UNCOV
166
        return this.loadedTables.length > 0 ? this.loadedTables[0] : undefined
×
167
    }
168

169
    /**
170
     * Loads all tables (with given names) from the database.
171
     */
172
    async getTables(tableNames?: string[]): Promise<Table[]> {
UNCOV
173
        if (!tableNames) {
×
174
            // Don't cache in this case.
175
            // This is the new case & isn't used anywhere else anyway.
UNCOV
176
            return await this.loadTables(tableNames)
×
177
        }
178

UNCOV
179
        this.loadedTables = await this.loadTables(tableNames)
×
UNCOV
180
        return this.loadedTables
×
181
    }
182

183
    /**
184
     * Loads given view's data from the database.
185
     */
186
    async getView(viewPath: string): Promise<View | undefined> {
UNCOV
187
        this.loadedViews = await this.loadViews([viewPath])
×
UNCOV
188
        return this.loadedViews.length > 0 ? this.loadedViews[0] : undefined
×
189
    }
190

191
    /**
192
     * Loads given view's data from the database.
193
     */
194
    async getViews(viewPaths?: string[]): Promise<View[]> {
UNCOV
195
        this.loadedViews = await this.loadViews(viewPaths)
×
UNCOV
196
        return this.loadedViews
×
197
    }
198

199
    /**
200
     * Enables special query runner mode in which sql queries won't be executed,
201
     * instead they will be memorized into a special variable inside query runner.
202
     * You can get memorized sql using getMemorySql() method.
203
     */
204
    enableSqlMemory(): void {
UNCOV
205
        this.sqlInMemory = new SqlInMemory()
×
UNCOV
206
        this.sqlMemoryMode = true
×
207
    }
208

209
    /**
210
     * Disables special query runner mode in which sql queries won't be executed
211
     * started by calling enableSqlMemory() method.
212
     *
213
     * Previously memorized sql will be flushed.
214
     */
215
    disableSqlMemory(): void {
UNCOV
216
        this.sqlInMemory = new SqlInMemory()
×
UNCOV
217
        this.sqlMemoryMode = false
×
218
    }
219

220
    /**
221
     * Flushes all memorized sqls.
222
     */
223
    clearSqlMemory(): void {
UNCOV
224
        this.sqlInMemory = new SqlInMemory()
×
225
    }
226

227
    /**
228
     * Gets sql stored in the memory. Parameters in the sql are already replaced.
229
     */
230
    getMemorySql(): SqlInMemory {
UNCOV
231
        return this.sqlInMemory
×
232
    }
233

234
    /**
235
     * Executes up sql queries.
236
     */
237
    async executeMemoryUpSql(): Promise<void> {
238
        for (const { query, parameters } of this.sqlInMemory.upQueries) {
×
239
            await this.query(query, parameters)
×
240
        }
241
    }
242

243
    /**
244
     * Executes down sql queries.
245
     */
246
    async executeMemoryDownSql(): Promise<void> {
UNCOV
247
        for (const {
×
248
            query,
249
            parameters,
250
        } of this.sqlInMemory.downQueries.reverse()) {
UNCOV
251
            await this.query(query, parameters)
×
252
        }
253
    }
254

255
    getReplicationMode(): ReplicationMode {
UNCOV
256
        return this.mode
×
257
    }
258

259
    // -------------------------------------------------------------------------
260
    // Protected Methods
261
    // -------------------------------------------------------------------------
262

263
    /**
264
     * Gets view from previously loaded views, otherwise loads it from database.
265
     */
266
    protected async getCachedView(viewName: string): Promise<View> {
UNCOV
267
        const view = this.loadedViews.find((view) => view.name === viewName)
×
UNCOV
268
        if (view) return view
×
269

270
        const foundViews = await this.loadViews([viewName])
×
271
        if (foundViews.length > 0) {
×
272
            this.loadedViews.push(foundViews[0])
×
273
            return foundViews[0]
×
274
        } else {
275
            throw new TypeORMError(`View "${viewName}" does not exist.`)
×
276
        }
277
    }
278

279
    /**
280
     * Gets table from previously loaded tables, otherwise loads it from database.
281
     */
282
    protected async getCachedTable(tableName: string): Promise<Table> {
UNCOV
283
        if (tableName in this.cachedTablePaths) {
×
UNCOV
284
            const tablePath = this.cachedTablePaths[tableName]
×
UNCOV
285
            const table = this.loadedTables.find(
×
UNCOV
286
                (table) => this.getTablePath(table) === tablePath,
×
287
            )
288

UNCOV
289
            if (table) {
×
UNCOV
290
                return table
×
291
            }
292
        }
293

UNCOV
294
        const foundTables = await this.loadTables([tableName])
×
295

UNCOV
296
        if (foundTables.length > 0) {
×
UNCOV
297
            const foundTablePath = this.getTablePath(foundTables[0])
×
298

UNCOV
299
            const cachedTable = this.loadedTables.find(
×
UNCOV
300
                (table) => this.getTablePath(table) === foundTablePath,
×
301
            )
302

UNCOV
303
            if (!cachedTable) {
×
UNCOV
304
                this.cachedTablePaths[tableName] = this.getTablePath(
×
305
                    foundTables[0],
306
                )
UNCOV
307
                this.loadedTables.push(foundTables[0])
×
UNCOV
308
                return foundTables[0]
×
309
            } else {
UNCOV
310
                return cachedTable
×
311
            }
312
        } else {
313
            throw new TypeORMError(`Table "${tableName}" does not exist.`)
×
314
        }
315
    }
316

317
    /**
318
     * Replaces loaded table with given changed table.
319
     */
320
    protected replaceCachedTable(table: Table, changedTable: Table): void {
UNCOV
321
        const oldTablePath = this.getTablePath(table)
×
UNCOV
322
        const foundTable = this.loadedTables.find(
×
UNCOV
323
            (loadedTable) => this.getTablePath(loadedTable) === oldTablePath,
×
324
        )
325

326
        // Clean up the lookup cache..
UNCOV
327
        for (const [key, cachedPath] of Object.entries(this.cachedTablePaths)) {
×
UNCOV
328
            if (cachedPath === oldTablePath) {
×
UNCOV
329
                this.cachedTablePaths[key] = this.getTablePath(changedTable)
×
330
            }
331
        }
332

UNCOV
333
        if (foundTable) {
×
UNCOV
334
            foundTable.database = changedTable.database
×
UNCOV
335
            foundTable.schema = changedTable.schema
×
UNCOV
336
            foundTable.name = changedTable.name
×
UNCOV
337
            foundTable.columns = changedTable.columns
×
UNCOV
338
            foundTable.indices = changedTable.indices
×
UNCOV
339
            foundTable.foreignKeys = changedTable.foreignKeys
×
UNCOV
340
            foundTable.uniques = changedTable.uniques
×
UNCOV
341
            foundTable.checks = changedTable.checks
×
UNCOV
342
            foundTable.justCreated = changedTable.justCreated
×
UNCOV
343
            foundTable.engine = changedTable.engine
×
UNCOV
344
            foundTable.comment = changedTable.comment
×
345
        }
346
    }
347

348
    protected getTablePath(
349
        target: EntityMetadata | Table | View | TableForeignKey | string,
350
    ): string {
UNCOV
351
        const parsed = this.connection.driver.parseTableName(target)
×
352

UNCOV
353
        return this.connection.driver.buildTableName(
×
354
            parsed.tableName,
355
            parsed.schema,
356
            parsed.database,
357
        )
358
    }
359

360
    protected getTypeormMetadataTableName(): string {
361
        const options = <
362
            SqlServerConnectionOptions | PostgresConnectionOptions
UNCOV
363
        >this.connection.driver.options
×
UNCOV
364
        return this.connection.driver.buildTableName(
×
365
            this.connection.metadataTableName,
366
            options.schema,
367
            options.database,
368
        )
369
    }
370

371
    /**
372
     * Generates SQL query to select record from typeorm metadata table.
373
     */
374
    protected selectTypeormMetadataSql({
375
        database,
376
        schema,
377
        table,
378
        type,
379
        name,
380
    }: {
381
        database?: string
382
        schema?: string
383
        table?: string
384
        type: MetadataTableType
385
        name: string
386
    }): Query {
UNCOV
387
        const qb = this.connection.createQueryBuilder()
×
UNCOV
388
        const selectQb = qb
×
389
            .select()
390
            .from(this.getTypeormMetadataTableName(), "t")
391
            .where(`${qb.escape("type")} = :type`, { type })
392
            .andWhere(`${qb.escape("name")} = :name`, { name })
393

UNCOV
394
        if (database) {
×
UNCOV
395
            selectQb.andWhere(`${qb.escape("database")} = :database`, {
×
396
                database,
397
            })
398
        }
399

UNCOV
400
        if (schema) {
×
UNCOV
401
            selectQb.andWhere(`${qb.escape("schema")} = :schema`, { schema })
×
402
        }
403

UNCOV
404
        if (table) {
×
UNCOV
405
            selectQb.andWhere(`${qb.escape("table")} = :table`, { table })
×
406
        }
407

UNCOV
408
        const [query, parameters] = selectQb.getQueryAndParameters()
×
UNCOV
409
        return new Query(query, parameters)
×
410
    }
411

412
    /**
413
     * Generates SQL query to insert a record into typeorm metadata table.
414
     */
415
    protected insertTypeormMetadataSql({
416
        database,
417
        schema,
418
        table,
419
        type,
420
        name,
421
        value,
422
    }: {
423
        database?: string
424
        schema?: string
425
        table?: string
426
        type: MetadataTableType
427
        name: string
428
        value?: string
429
    }): Query {
UNCOV
430
        const [query, parameters] = this.connection
×
431
            .createQueryBuilder()
432
            .insert()
433
            .into(this.getTypeormMetadataTableName())
434
            .values({
435
                database: database,
436
                schema: schema,
437
                table: table,
438
                type: type,
439
                name: name,
440
                value: value,
441
            })
442
            .getQueryAndParameters()
443

UNCOV
444
        return new Query(query, parameters)
×
445
    }
446

447
    /**
448
     * Generates SQL query to delete a record from typeorm metadata table.
449
     */
450
    protected deleteTypeormMetadataSql({
451
        database,
452
        schema,
453
        table,
454
        type,
455
        name,
456
    }: {
457
        database?: string
458
        schema?: string
459
        table?: string
460
        type: MetadataTableType
461
        name: string
462
    }): Query {
UNCOV
463
        const qb = this.connection.createQueryBuilder()
×
UNCOV
464
        const deleteQb = qb
×
465
            .delete()
466
            .from(this.getTypeormMetadataTableName())
467
            .where(`${qb.escape("type")} = :type`, { type })
468
            .andWhere(`${qb.escape("name")} = :name`, { name })
469

UNCOV
470
        if (database) {
×
UNCOV
471
            deleteQb.andWhere(`${qb.escape("database")} = :database`, {
×
472
                database,
473
            })
474
        }
475

UNCOV
476
        if (schema) {
×
UNCOV
477
            deleteQb.andWhere(`${qb.escape("schema")} = :schema`, { schema })
×
478
        }
479

UNCOV
480
        if (table) {
×
UNCOV
481
            deleteQb.andWhere(`${qb.escape("table")} = :table`, { table })
×
482
        }
483

UNCOV
484
        const [query, parameters] = deleteQb.getQueryAndParameters()
×
UNCOV
485
        return new Query(query, parameters)
×
486
    }
487

488
    /**
489
     * Checks if at least one of column properties was changed.
490
     * Does not checks column type, length and autoincrement, because these properties changes separately.
491
     */
492
    protected isColumnChanged(
493
        oldColumn: TableColumn,
494
        newColumn: TableColumn,
495
        checkDefault?: boolean,
496
        checkComment?: boolean,
497
        checkEnum = true,
×
498
    ): boolean {
499
        // this logs need to debug issues in column change detection. Do not delete it!
500

501
        // console.log("charset ---------------");
502
        // console.log(oldColumn.charset !== newColumn.charset);
503
        // console.log(oldColumn.charset, newColumn.charset);
504
        // console.log("collation ---------------");
505
        // console.log(oldColumn.collation !== newColumn.collation);
506
        // console.log(oldColumn.collation, newColumn.collation);
507
        // console.log("precision ---------------");
508
        // console.log(oldColumn.precision !== newColumn.precision);
509
        // console.log(oldColumn.precision, newColumn.precision);
510
        // console.log("scale ---------------");
511
        // console.log(oldColumn.scale !== newColumn.scale);
512
        // console.log(oldColumn.scale, newColumn.scale);
513
        // console.log("default ---------------");
514
        // console.log((checkDefault && oldColumn.default !== newColumn.default));
515
        // console.log(oldColumn.default, newColumn.default);
516
        // console.log("isNullable ---------------");
517
        // console.log(oldColumn.isNullable !== newColumn.isNullable);
518
        // console.log(oldColumn.isNullable, newColumn.isNullable);
519
        // console.log("comment ---------------");
520
        // console.log((checkComment && oldColumn.comment !== newColumn.comment));
521
        // console.log(oldColumn.comment, newColumn.comment);
522
        // console.log("enum ---------------");
523
        // console.log(!OrmUtils.isArraysEqual(oldColumn.enum || [], newColumn.enum || []));
524
        // console.log(oldColumn.enum, newColumn.enum);
525

UNCOV
526
        return (
×
527
            oldColumn.charset !== newColumn.charset ||
×
528
            oldColumn.collation !== newColumn.collation ||
529
            oldColumn.precision !== newColumn.precision ||
530
            oldColumn.scale !== newColumn.scale ||
531
            oldColumn.width !== newColumn.width || // MySQL only
532
            oldColumn.zerofill !== newColumn.zerofill || // MySQL only
533
            oldColumn.unsigned !== newColumn.unsigned || // MySQL only
534
            oldColumn.asExpression !== newColumn.asExpression ||
535
            (checkDefault && oldColumn.default !== newColumn.default) ||
536
            oldColumn.onUpdate !== newColumn.onUpdate || // MySQL only
537
            oldColumn.isNullable !== newColumn.isNullable ||
538
            (checkComment && oldColumn.comment !== newColumn.comment) ||
539
            (checkEnum && this.isEnumChanged(oldColumn, newColumn))
540
        )
541
    }
542

543
    protected isEnumChanged(oldColumn: TableColumn, newColumn: TableColumn) {
UNCOV
544
        return !OrmUtils.isArraysEqual(
×
545
            oldColumn.enum || [],
×
546
            newColumn.enum || [],
×
547
        )
548
    }
549

550
    /**
551
     * Checks if column length is by default.
552
     */
553
    protected isDefaultColumnLength(
554
        table: Table,
555
        column: TableColumn,
556
        length: string,
557
    ): boolean {
558
        // if table have metadata, we check if length is specified in column metadata
UNCOV
559
        if (this.connection.hasMetadata(table.name)) {
×
UNCOV
560
            const metadata = this.connection.getMetadata(table.name)
×
UNCOV
561
            const columnMetadata = metadata.findColumnWithDatabaseName(
×
562
                column.name,
563
            )
564

UNCOV
565
            if (columnMetadata) {
×
566
                const columnMetadataLength =
UNCOV
567
                    this.connection.driver.getColumnLength(columnMetadata)
×
UNCOV
568
                if (columnMetadataLength) return false
×
569
            }
570
        }
571

UNCOV
572
        if (
×
573
            this.connection.driver.dataTypeDefaults &&
×
574
            this.connection.driver.dataTypeDefaults[column.type] &&
575
            this.connection.driver.dataTypeDefaults[column.type].length
576
        ) {
UNCOV
577
            return (
×
578
                this.connection.driver.dataTypeDefaults[
579
                    column.type
580
                ].length!.toString() === length.toString()
581
            )
582
        }
583

UNCOV
584
        return false
×
585
    }
586

587
    /**
588
     * Checks if column precision is by default.
589
     */
590
    protected isDefaultColumnPrecision(
591
        table: Table,
592
        column: TableColumn,
593
        precision: number,
594
    ): boolean {
595
        // if table have metadata, we check if length is specified in column metadata
UNCOV
596
        if (this.connection.hasMetadata(table.name)) {
×
UNCOV
597
            const metadata = this.connection.getMetadata(table.name)
×
UNCOV
598
            const columnMetadata = metadata.findColumnWithDatabaseName(
×
599
                column.name,
600
            )
UNCOV
601
            if (
×
602
                columnMetadata &&
×
603
                columnMetadata.precision !== null &&
604
                columnMetadata.precision !== undefined
605
            )
UNCOV
606
                return false
×
607
        }
608

UNCOV
609
        if (
×
610
            this.connection.driver.dataTypeDefaults &&
×
611
            this.connection.driver.dataTypeDefaults[column.type] &&
612
            this.connection.driver.dataTypeDefaults[column.type].precision !==
613
                null &&
614
            this.connection.driver.dataTypeDefaults[column.type].precision !==
615
                undefined
616
        )
UNCOV
617
            return (
×
618
                this.connection.driver.dataTypeDefaults[column.type]
619
                    .precision === precision
620
            )
621

622
        return false
×
623
    }
624

625
    /**
626
     * Checks if column scale is by default.
627
     */
628
    protected isDefaultColumnScale(
629
        table: Table,
630
        column: TableColumn,
631
        scale: number,
632
    ): boolean {
633
        // if table have metadata, we check if length is specified in column metadata
UNCOV
634
        if (this.connection.hasMetadata(table.name)) {
×
UNCOV
635
            const metadata = this.connection.getMetadata(table.name)
×
UNCOV
636
            const columnMetadata = metadata.findColumnWithDatabaseName(
×
637
                column.name,
638
            )
UNCOV
639
            if (
×
640
                columnMetadata &&
×
641
                columnMetadata.scale !== null &&
642
                columnMetadata.scale !== undefined
643
            )
UNCOV
644
                return false
×
645
        }
646

UNCOV
647
        if (
×
648
            this.connection.driver.dataTypeDefaults &&
×
649
            this.connection.driver.dataTypeDefaults[column.type] &&
650
            this.connection.driver.dataTypeDefaults[column.type].scale !==
651
                null &&
652
            this.connection.driver.dataTypeDefaults[column.type].scale !==
653
                undefined
654
        )
UNCOV
655
            return (
×
656
                this.connection.driver.dataTypeDefaults[column.type].scale ===
657
                scale
658
            )
659

UNCOV
660
        return false
×
661
    }
662

663
    /**
664
     * Executes sql used special for schema build.
665
     */
666
    protected async executeQueries(
667
        upQueries: Query | Query[],
668
        downQueries: Query | Query[],
669
    ): Promise<void> {
UNCOV
670
        if (InstanceChecker.isQuery(upQueries)) upQueries = [upQueries]
×
UNCOV
671
        if (InstanceChecker.isQuery(downQueries)) downQueries = [downQueries]
×
672

UNCOV
673
        this.sqlInMemory.upQueries.push(...upQueries)
×
UNCOV
674
        this.sqlInMemory.downQueries.push(...downQueries)
×
675

676
        // if sql-in-memory mode is enabled then simply store sql in memory and return
UNCOV
677
        if (this.sqlMemoryMode === true)
×
UNCOV
678
            return Promise.resolve() as Promise<any>
×
679

UNCOV
680
        for (const { query, parameters } of upQueries) {
×
UNCOV
681
            await this.query(query, parameters)
×
682
        }
683
    }
684

685
    /**
686
     * Generated an index name for a table and index
687
     */
688
    protected generateIndexName(
689
        table: Table | View,
690
        index: TableIndex,
691
    ): string {
692
        // new index may be passed without name. In this case we generate index name manually.
UNCOV
693
        return this.connection.namingStrategy.indexName(
×
694
            table,
695
            index.columnNames,
696
            index.where,
697
        )
698
    }
699
}
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

© 2025 Coveralls, Inc