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

typeorm / typeorm / 19549987525

20 Nov 2025 08:11PM UTC coverage: 80.769% (+4.3%) from 76.433%
19549987525

push

github

web-flow
ci: run tests on commits to master and next (#11783)

Co-authored-by: Oleg "OSA413" Sokolov <OSA413@users.noreply.github.com>

26500 of 32174 branches covered (82.36%)

Branch coverage included in aggregate %.

91252 of 113615 relevant lines covered (80.32%)

88980.79 hits per line

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

41.83
/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
    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
    driver: AuroraPostgresDriver
26✔
35

26✔
36
    protected client: any
26✔
37

26✔
38
    // -------------------------------------------------------------------------
26✔
39
    // Protected Properties
26✔
40
    // -------------------------------------------------------------------------
26✔
41

26✔
42
    /**
26✔
43
     * Promise used to obtain a database connection for a first time.
26✔
44
     */
26✔
45
    protected databaseConnectionPromise: Promise<any>
26✔
46

26✔
47
    // -------------------------------------------------------------------------
26✔
48
    // Constructor
26✔
49
    // -------------------------------------------------------------------------
26✔
50

26✔
51
    constructor(
26✔
52
        driver: AuroraPostgresDriver,
×
53
        client: any,
×
54
        mode: ReplicationMode,
×
55
    ) {
×
56
        super(driver, mode)
×
57

×
58
        this.client = client
×
59
    }
×
60

26✔
61
    // -------------------------------------------------------------------------
26✔
62
    // Public Methods
26✔
63
    // -------------------------------------------------------------------------
26✔
64

26✔
65
    /**
26✔
66
     * Creates/uses database connection from the connection pool to perform further operations.
26✔
67
     * Returns obtained database connection.
26✔
68
     */
26✔
69
    connect(): Promise<any> {
26✔
70
        if (this.databaseConnection)
×
71
            return Promise.resolve(this.databaseConnection)
×
72

×
73
        if (this.databaseConnectionPromise)
×
74
            return this.databaseConnectionPromise
×
75

×
76
        if (this.mode === "slave" && this.driver.isReplicated) {
×
77
            this.databaseConnectionPromise = this.driver
×
78
                .obtainSlaveConnection()
×
79
                .then(([connection, release]: any[]) => {
×
80
                    this.driver.connectedQueryRunners.push(this)
×
81
                    this.databaseConnection = connection
×
82
                    this.releaseCallback = release
×
83
                    return this.databaseConnection
×
84
                })
×
85
        } else {
×
86
            // master
×
87
            this.databaseConnectionPromise = this.driver
×
88
                .obtainMasterConnection()
×
89
                .then(([connection, release]: any[]) => {
×
90
                    this.driver.connectedQueryRunners.push(this)
×
91
                    this.databaseConnection = connection
×
92
                    this.releaseCallback = release
×
93
                    return this.databaseConnection
×
94
                })
×
95
        }
×
96

×
97
        return this.databaseConnectionPromise
×
98
    }
×
99

26✔
100
    /**
26✔
101
     * Starts transaction on the current connection.
26✔
102
     */
26✔
103
    async startTransaction(isolationLevel?: IsolationLevel): Promise<void> {
26✔
104
        this.isTransactionActive = true
×
105
        try {
×
106
            await this.broadcaster.broadcast("BeforeTransactionStart")
×
107
        } catch (err) {
×
108
            this.isTransactionActive = false
×
109
            throw err
×
110
        }
×
111

×
112
        if (this.transactionDepth === 0) {
×
113
            await this.client.startTransaction()
×
114
        } else {
×
115
            await this.query(`SAVEPOINT typeorm_${this.transactionDepth}`)
×
116
        }
×
117
        this.transactionDepth += 1
×
118

×
119
        await this.broadcaster.broadcast("AfterTransactionStart")
×
120
    }
×
121

26✔
122
    /**
26✔
123
     * Commits transaction.
26✔
124
     * Error will be thrown if transaction was not started.
26✔
125
     */
26✔
126
    async commitTransaction(): Promise<void> {
26✔
127
        if (!this.isTransactionActive) throw new TransactionNotStartedError()
×
128

×
129
        await this.broadcaster.broadcast("BeforeTransactionCommit")
×
130

×
131
        if (this.transactionDepth > 1) {
×
132
            await this.query(
×
133
                `RELEASE SAVEPOINT typeorm_${this.transactionDepth - 1}`,
×
134
            )
×
135
        } else {
×
136
            await this.client.commitTransaction()
×
137
            this.isTransactionActive = false
×
138
        }
×
139
        this.transactionDepth -= 1
×
140

×
141
        await this.broadcaster.broadcast("AfterTransactionCommit")
×
142
    }
×
143

26✔
144
    /**
26✔
145
     * Rollbacks transaction.
26✔
146
     * Error will be thrown if transaction was not started.
26✔
147
     */
26✔
148
    async rollbackTransaction(): Promise<void> {
26✔
149
        if (!this.isTransactionActive) throw new TransactionNotStartedError()
×
150

×
151
        await this.broadcaster.broadcast("BeforeTransactionRollback")
×
152

×
153
        if (this.transactionDepth > 1) {
×
154
            await this.query(
×
155
                `ROLLBACK TO SAVEPOINT typeorm_${this.transactionDepth - 1}`,
×
156
            )
×
157
        } else {
×
158
            await this.client.rollbackTransaction()
×
159
            this.isTransactionActive = false
×
160
        }
×
161
        this.transactionDepth -= 1
×
162

×
163
        await this.broadcaster.broadcast("AfterTransactionRollback")
×
164
    }
×
165

26✔
166
    /**
26✔
167
     * Executes a given SQL query.
26✔
168
     */
26✔
169
    async query(
26✔
170
        query: string,
×
171
        parameters?: any[],
×
172
        useStructuredResult = false,
×
173
    ): Promise<any> {
×
174
        if (this.isReleased) throw new QueryRunnerAlreadyReleasedError()
×
175

×
176
        const raw = await this.client.query(query, parameters)
×
177

×
178
        const result = new QueryResult()
×
179

×
180
        result.raw = raw
×
181

×
182
        if (raw?.hasOwnProperty("records") && Array.isArray(raw.records)) {
×
183
            result.records = raw.records
×
184
        }
×
185

×
186
        if (raw?.hasOwnProperty("numberOfRecordsUpdated")) {
×
187
            result.affected = raw.numberOfRecordsUpdated
×
188
        }
×
189

×
190
        if (!useStructuredResult) {
×
191
            return result.raw
×
192
        }
×
193

×
194
        return result
×
195
    }
×
196

26✔
197
    /**
26✔
198
     * Change table comment.
26✔
199
     */
26✔
200
    changeTableComment(
26✔
201
        tableOrName: Table | string,
×
202
        comment?: string,
×
203
    ): Promise<void> {
×
204
        throw new TypeORMError(
×
205
            `aurora-postgres driver does not support change comment.`,
×
206
        )
×
207
    }
×
208
}
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