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

typeorm / typeorm / 13573761448

27 Feb 2025 06:53PM UTC coverage: 72.376% (+0.007%) from 72.369%
13573761448

push

github

web-flow
refactor: use ansis instead of chalk (#11263)

8657 of 12650 branches covered (68.43%)

Branch coverage included in aggregate %.

35 of 52 new or added lines in 11 files covered. (67.31%)

4 existing lines in 3 files now uncovered.

17895 of 24036 relevant lines covered (74.45%)

144036.91 hits per line

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

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

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

18
    builder(args: yargs.Argv) {
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

32
    async handler(args: yargs.Arguments) {
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 {
NEW
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
}
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