• 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

27.16
/src/commands/QueryCommand.ts
1
import ansi from "ansis"
26✔
2
import path from "path"
26✔
3
import process from "process"
26✔
4
import yargs from "yargs"
26✔
5
import { DataSource } from "../data-source/DataSource"
26✔
6
import { PlatformTools } from "../platform/PlatformTools"
26✔
7
import { QueryRunner } from "../query-runner/QueryRunner"
26✔
8
import { CommandUtils } from "./CommandUtils"
26✔
9

26✔
10
/**
26✔
11
 * Executes an SQL query on the given dataSource.
26✔
12
 */
26✔
13
export class QueryCommand implements yargs.CommandModule {
208✔
14
    command = "query [query]"
208✔
15
    describe =
208✔
16
        "Executes given SQL query on a default dataSource. Specify connection name to run query on a specific dataSource."
208✔
17

208✔
18
    builder(args: yargs.Argv) {
208✔
19
        return args
×
20
            .positional("query", {
×
21
                describe: "The SQL Query to run",
×
22
                type: "string",
×
23
            })
×
24
            .option("dataSource", {
×
25
                alias: "d",
×
26
                describe:
×
27
                    "Path to the file where your DataSource instance is defined.",
×
28
                demandOption: true,
×
29
            })
×
30
    }
×
31

208✔
32
    async handler(args: yargs.Arguments) {
208✔
33
        let queryRunner: QueryRunner | undefined = undefined
×
34
        let dataSource: DataSource | undefined = undefined
×
35
        try {
×
36
            dataSource = await CommandUtils.loadDataSource(
×
37
                path.resolve(process.cwd(), args.dataSource as string),
×
38
            )
×
39
            dataSource.setOptions({
×
40
                synchronize: false,
×
41
                migrationsRun: false,
×
42
                dropSchema: false,
×
43
                logging: false,
×
44
            })
×
45
            await dataSource.initialize()
×
46

×
47
            // create a query runner and execute query using it
×
48
            queryRunner = dataSource.createQueryRunner()
×
49
            const query = args.query as string
×
50
            console.log(
×
51
                ansi.green`Running query: ` + PlatformTools.highlightSql(query),
×
52
            )
×
53
            const queryResult = await queryRunner.query(query)
×
54

×
55
            if (typeof queryResult === "undefined") {
×
56
                console.log(
×
57
                    ansi.green`Query has been executed. No result was returned.`,
×
58
                )
×
59
            } else {
×
60
                console.log(ansi.green`Query has been executed. Result: `)
×
61
                console.dir(queryResult, {
×
62
                    breakLength: Infinity,
×
63
                    compact: false,
×
64
                    depth: null,
×
65
                })
×
66
            }
×
67

×
68
            await queryRunner.release()
×
69
            await dataSource.destroy()
×
70
        } catch (err) {
×
71
            PlatformTools.logCmdErr("Error during query execution:", err)
×
72

×
73
            if (queryRunner) await (queryRunner as QueryRunner).release()
×
74
            if (dataSource && dataSource.isInitialized)
×
75
                await dataSource.destroy()
×
76

×
77
            process.exit(1)
×
78
        }
×
79
    }
×
80
}
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

© 2026 Coveralls, Inc