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

typeorm / typeorm / 16405830134

21 Jul 2025 12:22AM UTC coverage: 76.442% (+0.002%) from 76.44%
16405830134

Pull #11576

github

web-flow
Merge ccddce2d3 into d57fe3bd8
Pull Request #11576: fix(sqlserver): queries returning multiple record sets

9324 of 12885 branches covered (72.36%)

Branch coverage included in aggregate %.

55 of 78 new or added lines in 25 files covered. (70.51%)

2073 existing lines in 24 files now uncovered.

19016 of 24189 relevant lines covered (78.61%)

119538.23 hits per line

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

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

12
class PostgresQueryRunnerWrapper extends PostgresQueryRunner {
13
    driver: any
14

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

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

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

36
    protected client: any
37

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

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

47
    // -------------------------------------------------------------------------
48
    // Constructor
49
    // -------------------------------------------------------------------------
50

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

UNCOV
58
        this.client = client
×
59
    }
60

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

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

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

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

UNCOV
97
        return this.databaseConnectionPromise
×
98
    }
99

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

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

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

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

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

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

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

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

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

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

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

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

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

NEW
178
        const result = new QueryResult()
×
179

UNCOV
180
        result.raw = raw
×
181

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

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

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

UNCOV
194
        return result
×
195
    }
196

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