• 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

11.29
/src/driver/react-native/ReactNativeQueryRunner.ts
1
import { ObjectLiteral } from "../../common/ObjectLiteral"
2
import { QueryFailedError } from "../../error/QueryFailedError"
24✔
3
import { QueryRunnerAlreadyReleasedError } from "../../error/QueryRunnerAlreadyReleasedError"
24✔
4
import { QueryResult } from "../../query-runner/QueryResult"
24✔
5
import { Broadcaster } from "../../subscriber/Broadcaster"
24✔
6
import { BroadcasterResult } from "../../subscriber/BroadcasterResult"
24✔
7
import { AbstractSqliteQueryRunner } from "../sqlite-abstract/AbstractSqliteQueryRunner"
24✔
8
import { ReactNativeDriver } from "./ReactNativeDriver"
9

10
/**
11
 * Runs queries on a single sqlite database connection.
12
 */
13
export class ReactNativeQueryRunner extends AbstractSqliteQueryRunner {
24✔
14
    /**
15
     * Database driver used by connection.
16
     */
17
    // @ts-ignore temporary, we need to fix the issue with the AbstractSqliteDriver and circular errors
18
    driver: ReactNativeDriver
19

20
    // -------------------------------------------------------------------------
21
    // Constructor
22
    // -------------------------------------------------------------------------
23

24
    constructor(driver: ReactNativeDriver) {
UNCOV
25
        super()
×
26
        this.driver = driver
×
27
        this.connection = driver.connection
×
28
        this.broadcaster = new Broadcaster(this)
×
29
    }
30

31
    /**
32
     * Called before migrations are run.
33
     */
34
    async beforeMigration(): Promise<void> {
UNCOV
35
        await this.query(`PRAGMA foreign_keys = OFF`)
×
36
    }
37

38
    /**
39
     * Called after migrations are run.
40
     */
41
    async afterMigration(): Promise<void> {
UNCOV
42
        await this.query(`PRAGMA foreign_keys = ON`)
×
43
    }
44

45
    /**
46
     * Executes a given SQL query.
47
     */
48
    async query(
49
        query: string,
50
        parameters?: any[],
51
        useStructuredResult = false,
×
52
    ): Promise<any> {
UNCOV
53
        if (this.isReleased) throw new QueryRunnerAlreadyReleasedError()
×
54

NEW
55
        const databaseConnection = await this.connect()
×
56

NEW
57
        this.driver.connection.logger.logQuery(query, parameters, this)
×
UNCOV
58
        await this.broadcaster.broadcast("BeforeQuery", query, parameters)
×
59

60
        const broadcasterResult = new BroadcasterResult()
×
61

62
        const queryStartTime = Date.now()
×
63

UNCOV
64
        return new Promise(async (ok, fail) => {
×
65
            try {
×
UNCOV
66
                databaseConnection.executeSql(
×
67
                    query,
68
                    parameters,
69
                    async (raw: any) => {
70
                        // log slow queries if maxQueryExecution time is set
71
                        const maxQueryExecutionTime =
UNCOV
72
                            this.driver.options.maxQueryExecutionTime
×
UNCOV
73
                        const queryEndTime = Date.now()
×
UNCOV
74
                        const queryExecutionTime = queryEndTime - queryStartTime
×
UNCOV
75
                        this.broadcaster.broadcastAfterQueryEvent(
×
76
                            broadcasterResult,
77
                            query,
78
                            parameters,
79
                            true,
80
                            queryExecutionTime,
81
                            raw,
82
                            undefined,
83
                        )
84

UNCOV
85
                        if (
×
86
                            maxQueryExecutionTime &&
×
87
                            queryExecutionTime > maxQueryExecutionTime
88
                        )
UNCOV
89
                            this.driver.connection.logger.logQuerySlow(
×
90
                                queryExecutionTime,
91
                                query,
92
                                parameters,
93
                                this,
94
                            )
95

UNCOV
96
                        if (broadcasterResult.promises.length > 0)
×
UNCOV
97
                            await Promise.all(broadcasterResult.promises)
×
98

UNCOV
99
                        const result = new QueryResult()
×
100

101
                        if (raw?.hasOwnProperty("rowsAffected")) {
×
102
                            result.affected = raw.rowsAffected
×
103
                        }
104

UNCOV
105
                        if (raw?.hasOwnProperty("rows")) {
×
106
                            const records = []
×
107
                            for (let i = 0; i < raw.rows.length; i++) {
×
UNCOV
108
                                records.push(raw.rows.item(i))
×
109
                            }
110

111
                            result.raw = records
×
112
                            result.records = records
×
113
                        }
114

115
                        // return id of inserted row, if query was insert statement.
116
                        if (query.substr(0, 11) === "INSERT INTO") {
×
117
                            result.raw = raw.insertId
×
118
                        }
119

UNCOV
120
                        if (useStructuredResult) {
×
121
                            ok(result)
×
122
                        } else {
UNCOV
123
                            ok(result.raw)
×
124
                        }
125
                    },
126
                    (err: any) => {
UNCOV
127
                        this.driver.connection.logger.logQueryError(
×
128
                            err,
129
                            query,
130
                            parameters,
131
                            this,
132
                        )
UNCOV
133
                        this.broadcaster.broadcastAfterQueryEvent(
×
134
                            broadcasterResult,
135
                            query,
136
                            parameters,
137
                            false,
138
                            undefined,
139
                            undefined,
140
                            err,
141
                        )
142

UNCOV
143
                        fail(new QueryFailedError(query, parameters, err))
×
144
                    },
145
                )
146
            } catch (err) {
UNCOV
147
                fail(err)
×
148
            } finally {
UNCOV
149
                await broadcasterResult.wait()
×
150
            }
151
        })
152
    }
153

154
    // -------------------------------------------------------------------------
155
    // Protected Methods
156
    // -------------------------------------------------------------------------
157

158
    /**
159
     * Parametrizes given object of values. Used to create column=value queries.
160
     */
161
    protected parametrize(
162
        objectLiteral: ObjectLiteral,
163
        startIndex: number = 0,
×
164
    ): string[] {
UNCOV
165
        return Object.keys(objectLiteral).map((key, index) => `"${key}"` + "=?")
×
166
    }
167
}
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