• 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

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

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

26✔
20
    // -------------------------------------------------------------------------
26✔
21
    // Constructor
26✔
22
    // -------------------------------------------------------------------------
26✔
23

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

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

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

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

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

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

×
60
        const broadcasterResult = new BroadcasterResult()
×
61

×
62
        const queryStartTime = Date.now()
×
63

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

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

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

×
99
                        const result = new QueryResult()
×
100

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

×
105
                        if (raw?.hasOwnProperty("rows")) {
×
106
                            const records = []
×
107
                            for (let i = 0; i < raw.rows.length; i++) {
×
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

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

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

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

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