• 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

39.2
/src/driver/aurora-postgres/AuroraPostgresQueryRunner.ts
1
import { QueryRunnerAlreadyReleasedError } from "../../error/QueryRunnerAlreadyReleasedError"
26✔
2
import { TransactionNotStartedError } from "../../error/TransactionNotStartedError"
26✔
3
import { QueryRunner } from "../../query-runner/QueryRunner"
26✔
4
import { IsolationLevel } from "../types/IsolationLevel"
26✔
5
import { AuroraPostgresDriver } from "./AuroraPostgresDriver"
26✔
6
import { PostgresQueryRunner } from "../postgres/PostgresQueryRunner"
26✔
7
import { ReplicationMode } from "../types/ReplicationMode"
26✔
8
import { QueryResult } from "../../query-runner/QueryResult"
26✔
9
import { Table } from "../../schema-builder/table/Table"
26✔
10
import { TypeORMError } from "../../error"
26✔
11

26✔
12
class PostgresQueryRunnerWrapper extends PostgresQueryRunner {
26✔
13
    declare driver: any
26✔
14

26✔
15
    constructor(driver: any, mode: ReplicationMode) {
26✔
16
        super(driver, mode)
×
17
    }
×
18
}
26✔
19

26✔
20
/**
26✔
21
 * Runs queries on a single postgres database connection.
26✔
22
 */
26✔
23
export class AuroraPostgresQueryRunner
26✔
24
    extends PostgresQueryRunnerWrapper
26✔
25
    implements QueryRunner
26✔
26
{
26✔
27
    // -------------------------------------------------------------------------
26✔
28
    // Public Implemented Properties
26✔
29
    // -------------------------------------------------------------------------
26✔
30

26✔
31
    /**
26✔
32
     * Database driver used by connection.
26✔
33
     */
26✔
34
    declare driver: AuroraPostgresDriver
26✔
35

26✔
36
    protected client: any
26✔
37

26✔
38
    // -------------------------------------------------------------------------
26✔
39
    // Constructor
26✔
40
    // -------------------------------------------------------------------------
26✔
41

26✔
42
    constructor(
26✔
UNCOV
43
        driver: AuroraPostgresDriver,
×
UNCOV
44
        client: any,
×
UNCOV
45
        mode: ReplicationMode,
×
UNCOV
46
    ) {
×
UNCOV
47
        super(driver, mode)
×
UNCOV
48

×
UNCOV
49
        this.client = client
×
UNCOV
50
    }
×
51

26✔
52
    // -------------------------------------------------------------------------
26✔
53
    // Public Methods
26✔
54
    // -------------------------------------------------------------------------
26✔
55

26✔
56
    /**
26✔
57
     * Creates/uses database connection from the connection pool to perform further operations.
26✔
58
     * Returns obtained database connection.
26✔
59
     */
26✔
60
    connect(): Promise<any> {
26✔
UNCOV
61
        if (this.databaseConnection)
×
UNCOV
62
            return Promise.resolve(this.databaseConnection)
×
UNCOV
63

×
UNCOV
64
        if (this.databaseConnectionPromise)
×
UNCOV
65
            return this.databaseConnectionPromise
×
UNCOV
66

×
UNCOV
67
        if (this.mode === "slave" && this.driver.isReplicated) {
×
UNCOV
68
            this.databaseConnectionPromise = this.driver
×
UNCOV
69
                .obtainSlaveConnection()
×
70
                .then(([connection, release]: any[]) => {
×
71
                    this.driver.connectedQueryRunners.push(this)
×
72
                    this.databaseConnection = connection
×
73
                    this.releaseCallback = release
×
74
                    return this.databaseConnection
×
75
                })
×
76
        } else {
×
77
            // master
×
78
            this.databaseConnectionPromise = this.driver
×
79
                .obtainMasterConnection()
×
80
                .then(([connection, release]: any[]) => {
×
81
                    this.driver.connectedQueryRunners.push(this)
×
82
                    this.databaseConnection = connection
×
83
                    this.releaseCallback = release
×
84
                    return this.databaseConnection
×
85
                })
×
86
        }
×
87

×
88
        return this.databaseConnectionPromise
×
89
    }
×
90

26✔
91
    /**
26✔
92
     * Starts transaction on the current connection.
26✔
93
     */
26✔
94
    async startTransaction(isolationLevel?: IsolationLevel): Promise<void> {
26✔
95
        this.isTransactionActive = true
×
96
        try {
×
97
            await this.broadcaster.broadcast("BeforeTransactionStart")
×
98
        } catch (err) {
×
UNCOV
99
            this.isTransactionActive = false
×
UNCOV
100
            throw err
×
UNCOV
101
        }
×
UNCOV
102

×
UNCOV
103
        if (this.transactionDepth === 0) {
×
104
            await this.client.startTransaction()
×
105
        } else {
×
106
            await this.query(`SAVEPOINT typeorm_${this.transactionDepth}`)
×
107
        }
×
108
        this.transactionDepth += 1
×
109

×
110
        await this.broadcaster.broadcast("AfterTransactionStart")
×
111
    }
×
112

26✔
113
    /**
26✔
114
     * Commits transaction.
26✔
115
     * Error will be thrown if transaction was not started.
26✔
116
     */
26✔
117
    async commitTransaction(): Promise<void> {
26✔
118
        if (!this.isTransactionActive) throw new TransactionNotStartedError()
×
119

×
120
        await this.broadcaster.broadcast("BeforeTransactionCommit")
×
UNCOV
121

×
UNCOV
122
        if (this.transactionDepth > 1) {
×
UNCOV
123
            await this.query(
×
UNCOV
124
                `RELEASE SAVEPOINT typeorm_${this.transactionDepth - 1}`,
×
UNCOV
125
            )
×
UNCOV
126
        } else {
×
127
            await this.client.commitTransaction()
×
128
            this.isTransactionActive = false
×
129
        }
×
130
        this.transactionDepth -= 1
×
131

×
132
        await this.broadcaster.broadcast("AfterTransactionCommit")
×
133
    }
×
134

26✔
135
    /**
26✔
136
     * Rollbacks transaction.
26✔
137
     * Error will be thrown if transaction was not started.
26✔
138
     */
26✔
139
    async rollbackTransaction(): Promise<void> {
26✔
140
        if (!this.isTransactionActive) throw new TransactionNotStartedError()
×
141

×
142
        await this.broadcaster.broadcast("BeforeTransactionRollback")
×
UNCOV
143

×
UNCOV
144
        if (this.transactionDepth > 1) {
×
UNCOV
145
            await this.query(
×
UNCOV
146
                `ROLLBACK TO SAVEPOINT typeorm_${this.transactionDepth - 1}`,
×
UNCOV
147
            )
×
UNCOV
148
        } else {
×
149
            await this.client.rollbackTransaction()
×
150
            this.isTransactionActive = false
×
151
        }
×
152
        this.transactionDepth -= 1
×
153

×
154
        await this.broadcaster.broadcast("AfterTransactionRollback")
×
155
    }
×
156

26✔
157
    /**
26✔
158
     * Executes a given SQL query.
26✔
159
     */
26✔
160
    async query(
26✔
161
        query: string,
×
162
        parameters?: any[],
×
163
        useStructuredResult = false,
×
164
    ): Promise<any> {
×
UNCOV
165
        if (this.isReleased) throw new QueryRunnerAlreadyReleasedError()
×
UNCOV
166

×
UNCOV
167
        const raw = await this.client.query(query, parameters)
×
UNCOV
168

×
UNCOV
169
        const result = new QueryResult()
×
170

×
171
        result.raw = raw
×
172

×
173
        if (raw?.hasOwnProperty("records") && Array.isArray(raw.records)) {
×
174
            result.records = raw.records
×
175
        }
×
176

×
177
        if (raw?.hasOwnProperty("numberOfRecordsUpdated")) {
×
178
            result.affected = raw.numberOfRecordsUpdated
×
179
        }
×
180

×
181
        if (!useStructuredResult) {
×
182
            return result.raw
×
183
        }
×
184

×
185
        return result
×
186
    }
×
187

26✔
188
    /**
26✔
189
     * Change table comment.
26✔
190
     */
26✔
191
    changeTableComment(
26✔
192
        tableOrName: Table | string,
×
193
        comment?: string,
×
194
    ): Promise<void> {
×
195
        throw new TypeORMError(
×
UNCOV
196
            `aurora-postgres driver does not support change comment.`,
×
UNCOV
197
        )
×
UNCOV
198
    }
×
199
}
26✔
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