• 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

90.1
/src/driver/sqlite/SqliteQueryRunner.ts
1
import { ConnectionIsNotSetError } from "../../error/ConnectionIsNotSetError"
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 { SqliteConnectionOptions } from "./SqliteConnectionOptions"
26✔
9
import { SqliteDriver } from "./SqliteDriver"
26✔
10

26✔
11
/**
26✔
12
 * Runs queries on a single sqlite database connection.
26✔
13
 *
26✔
14
 * Does not support compose primary keys with autoincrement field.
26✔
15
 * todo: need to throw exception for this case.
26✔
16
 */
26✔
17
export class SqliteQueryRunner extends AbstractSqliteQueryRunner {
26✔
18
    /**
26✔
19
     * Database driver used by connection.
26✔
20
     */
26✔
21
    driver: SqliteDriver
26✔
22

26✔
23
    // -------------------------------------------------------------------------
26✔
24
    // Constructor
26✔
25
    // -------------------------------------------------------------------------
26✔
26

26✔
27
    constructor(driver: SqliteDriver) {
26✔
28
        super()
1,488✔
29
        this.driver = driver
1,488✔
30
        this.connection = driver.connection
1,488✔
31
        this.broadcaster = new Broadcaster(this)
1,488✔
32
    }
1,488✔
33

26✔
34
    /**
26✔
35
     * Called before migrations are run.
26✔
36
     */
26✔
37
    async beforeMigration(): Promise<void> {
26✔
38
        await this.query(`PRAGMA foreign_keys = OFF`)
4,353✔
39
    }
4,353✔
40

26✔
41
    /**
26✔
42
     * Called after migrations are run.
26✔
43
     */
26✔
44
    async afterMigration(): Promise<void> {
26✔
45
        await this.query(`PRAGMA foreign_keys = ON`)
4,344✔
46
    }
4,344✔
47

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

223,830✔
58
        const connection = this.driver.connection
223,830✔
59
        const options = connection.options as SqliteConnectionOptions
223,830✔
60
        const maxQueryExecutionTime = this.driver.options.maxQueryExecutionTime
223,830✔
61
        const broadcaster = this.broadcaster
223,830✔
62

223,830✔
63
        if (!connection.isInitialized) {
223,830✔
64
            throw new ConnectionIsNotSetError("sqlite")
3✔
65
        }
3✔
66

223,827✔
67
        const databaseConnection = await this.connect()
223,827✔
68

223,827✔
69
        this.driver.connection.logger.logQuery(query, parameters, this)
223,827✔
70
        await broadcaster.broadcast("BeforeQuery", query, parameters)
223,827✔
71

223,827✔
72
        const broadcasterResult = new BroadcasterResult()
223,827✔
73

223,827✔
74
        return new Promise(async (ok, fail) => {
223,827✔
75
            try {
223,827✔
76
                const queryStartTime = Date.now()
223,827✔
77
                const isInsertQuery = query.startsWith("INSERT ")
223,827✔
78
                const isDeleteQuery = query.startsWith("DELETE ")
223,827✔
79
                const isUpdateQuery = query.startsWith("UPDATE ")
223,827✔
80

223,827✔
81
                const execute = async () => {
223,827✔
82
                    if (isInsertQuery || isDeleteQuery || isUpdateQuery) {
223,827✔
83
                        await databaseConnection.run(query, parameters, handler)
36,576✔
84
                    } else {
223,827✔
85
                        await databaseConnection.all(query, parameters, handler)
187,251✔
86
                    }
187,251✔
87
                }
223,827✔
88

223,827✔
89
                const self = this
223,827✔
90
                const handler = function (this: any, err: any, rows: any) {
223,827✔
91
                    if (err && err.toString().indexOf("SQLITE_BUSY:") !== -1) {
223,827!
92
                        if (
×
93
                            typeof options.busyErrorRetry === "number" &&
×
94
                            options.busyErrorRetry > 0
×
95
                        ) {
×
96
                            setTimeout(execute, options.busyErrorRetry)
×
97
                            return
×
98
                        }
×
99
                    }
×
100

223,827✔
101
                    // log slow queries if maxQueryExecution time is set
223,827✔
102
                    const queryEndTime = Date.now()
223,827✔
103
                    const queryExecutionTime = queryEndTime - queryStartTime
223,827✔
104
                    if (
223,827✔
105
                        maxQueryExecutionTime &&
223,827!
106
                        queryExecutionTime > maxQueryExecutionTime
×
107
                    )
223,827✔
108
                        connection.logger.logQuerySlow(
223,827!
109
                            queryExecutionTime,
×
110
                            query,
×
111
                            parameters,
×
112
                            self,
×
113
                        )
×
114

223,827✔
115
                    if (err) {
223,827✔
116
                        connection.logger.logQueryError(
27✔
117
                            err,
27✔
118
                            query,
27✔
119
                            parameters,
27✔
120
                            self,
27✔
121
                        )
27✔
122
                        broadcaster.broadcastAfterQueryEvent(
27✔
123
                            broadcasterResult,
27✔
124
                            query,
27✔
125
                            parameters,
27✔
126
                            false,
27✔
127
                            undefined,
27✔
128
                            undefined,
27✔
129
                            err,
27✔
130
                        )
27✔
131

27✔
132
                        return fail(
27✔
133
                            new QueryFailedError(query, parameters, err),
27✔
134
                        )
27✔
135
                    } else {
223,827✔
136
                        const result = new QueryResult()
223,800✔
137

223,800✔
138
                        if (isInsertQuery) {
223,800✔
139
                            result.raw = this["lastID"]
34,206✔
140
                        } else {
223,800✔
141
                            result.raw = rows
189,594✔
142
                        }
189,594✔
143

223,800✔
144
                        broadcaster.broadcastAfterQueryEvent(
223,800✔
145
                            broadcasterResult,
223,800✔
146
                            query,
223,800✔
147
                            parameters,
223,800✔
148
                            true,
223,800✔
149
                            queryExecutionTime,
223,800✔
150
                            result.raw,
223,800✔
151
                            undefined,
223,800✔
152
                        )
223,800✔
153

223,800✔
154
                        if (Array.isArray(rows)) {
223,800✔
155
                            result.records = rows
187,242✔
156
                        }
187,242✔
157

223,800✔
158
                        result.affected = this["changes"]
223,800✔
159

223,800✔
160
                        if (useStructuredResult) {
223,800✔
161
                            ok(result)
52,140✔
162
                        } else {
223,800✔
163
                            ok(result.raw)
171,660✔
164
                        }
171,660✔
165
                    }
223,800✔
166
                }
223,827✔
167

223,827✔
168
                await execute()
223,827✔
169
            } catch (err) {
223,827!
170
                fail(err)
×
171
            } finally {
223,827✔
172
                await broadcasterResult.wait()
223,827✔
173
            }
223,827✔
174
        })
223,827✔
175
    }
223,827✔
176
}
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