• 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

80.84
/src/connection/options-reader/ConnectionOptionsEnvReader.ts
1
import { DataSourceOptions } from "../../data-source/DataSourceOptions"
26✔
2
import { PlatformTools } from "../../platform/PlatformTools"
26✔
3
import { OrmUtils } from "../../util/OrmUtils"
26✔
4

26✔
5
/**
26✔
6
 * Reads connection options from environment variables.
26✔
7
 * Environment variables can have only a single connection.
26✔
8
 * Its strongly required to define TYPEORM_CONNECTION env variable.
26✔
9
 *
26✔
10
 * @deprecated
26✔
11
 */
26✔
12
export class ConnectionOptionsEnvReader {
26✔
13
    // -------------------------------------------------------------------------
26✔
14
    // Public Methods
26✔
15
    // -------------------------------------------------------------------------
26✔
16

26✔
17
    /**
26✔
18
     * Reads connection options from environment variables.
26✔
19
     */
26✔
20
    read(): DataSourceOptions[] {
26✔
21
        return [
78✔
22
            {
78✔
23
                type:
78✔
24
                    PlatformTools.getEnvVariable("TYPEORM_CONNECTION") ||
78!
25
                    (PlatformTools.getEnvVariable("TYPEORM_URL")
×
26
                        ? PlatformTools.getEnvVariable("TYPEORM_URL").split(
×
27
                              "://",
×
28
                          )[0]
×
29
                        : undefined),
78✔
30
                url: PlatformTools.getEnvVariable("TYPEORM_URL"),
78✔
31
                host: PlatformTools.getEnvVariable("TYPEORM_HOST"),
78✔
32
                port: this.stringToNumber(
78✔
33
                    PlatformTools.getEnvVariable("TYPEORM_PORT"),
78✔
34
                ),
78✔
35
                username: PlatformTools.getEnvVariable("TYPEORM_USERNAME"),
78✔
36
                password: PlatformTools.getEnvVariable("TYPEORM_PASSWORD"),
78✔
37
                database: PlatformTools.getEnvVariable("TYPEORM_DATABASE"),
78✔
38
                sid: PlatformTools.getEnvVariable("TYPEORM_SID"),
78✔
39
                schema: PlatformTools.getEnvVariable("TYPEORM_SCHEMA"),
78✔
40
                extra: PlatformTools.getEnvVariable("TYPEORM_DRIVER_EXTRA")
78✔
41
                    ? JSON.parse(
78!
42
                          PlatformTools.getEnvVariable("TYPEORM_DRIVER_EXTRA"),
×
43
                      )
78✔
44
                    : undefined,
78✔
45
                synchronize: OrmUtils.toBoolean(
78✔
46
                    PlatformTools.getEnvVariable("TYPEORM_SYNCHRONIZE"),
78✔
47
                ),
78✔
48
                dropSchema: OrmUtils.toBoolean(
78✔
49
                    PlatformTools.getEnvVariable("TYPEORM_DROP_SCHEMA"),
78✔
50
                ),
78✔
51
                migrationsRun: OrmUtils.toBoolean(
78✔
52
                    PlatformTools.getEnvVariable("TYPEORM_MIGRATIONS_RUN"),
78✔
53
                ),
78✔
54
                entities: this.stringToArray(
78✔
55
                    PlatformTools.getEnvVariable("TYPEORM_ENTITIES"),
78✔
56
                ),
78✔
57
                migrations: this.stringToArray(
78✔
58
                    PlatformTools.getEnvVariable("TYPEORM_MIGRATIONS"),
78✔
59
                ),
78✔
60
                migrationsTableName: PlatformTools.getEnvVariable(
78✔
61
                    "TYPEORM_MIGRATIONS_TABLE_NAME",
78✔
62
                ),
78✔
63
                metadataTableName: PlatformTools.getEnvVariable(
78✔
64
                    "TYPEORM_METADATA_TABLE_NAME",
78✔
65
                ),
78✔
66
                subscribers: this.stringToArray(
78✔
67
                    PlatformTools.getEnvVariable("TYPEORM_SUBSCRIBERS"),
78✔
68
                ),
78✔
69
                logging: this.transformLogging(
78✔
70
                    PlatformTools.getEnvVariable("TYPEORM_LOGGING"),
78✔
71
                ),
78✔
72
                logger: PlatformTools.getEnvVariable("TYPEORM_LOGGER"),
78✔
73
                entityPrefix: PlatformTools.getEnvVariable(
78✔
74
                    "TYPEORM_ENTITY_PREFIX",
78✔
75
                ),
78✔
76
                maxQueryExecutionTime: PlatformTools.getEnvVariable(
78✔
77
                    "TYPEORM_MAX_QUERY_EXECUTION_TIME",
78✔
78
                ),
78✔
79
                debug: PlatformTools.getEnvVariable("TYPEORM_DEBUG"),
78✔
80
                cache: this.transformCaching(),
78✔
81
                uuidExtension: PlatformTools.getEnvVariable(
78✔
82
                    "TYPEORM_UUID_EXTENSION",
78✔
83
                ),
78✔
84
            },
78✔
85
        ]
78✔
86
    }
78✔
87

26✔
88
    // -------------------------------------------------------------------------
26✔
89
    // Protected Methods
26✔
90
    // -------------------------------------------------------------------------
26✔
91

26✔
92
    /**
26✔
93
     * Transforms logging string into real logging value connection requires.
26✔
94
     */
26✔
95
    protected transformLogging(logging: string): any {
26✔
96
        if (logging === "true" || logging === "TRUE" || logging === "1")
78✔
97
            return true
78!
98
        if (logging === "all") return "all"
78!
99

78✔
100
        return this.stringToArray(logging)
78✔
101
    }
78✔
102

26✔
103
    /**
26✔
104
     * Transforms caching option into real caching value option requires.
26✔
105
     */
26✔
106
    protected transformCaching(): boolean | object | undefined {
26✔
107
        const caching = PlatformTools.getEnvVariable("TYPEORM_CACHE")
78✔
108
        if (caching === "true" || caching === "TRUE" || caching === "1")
78✔
109
            return true
78!
110
        if (caching === "false" || caching === "FALSE" || caching === "0")
78✔
111
            return false
78!
112
        if (
78✔
113
            caching === "redis" ||
78✔
114
            caching === "ioredis" ||
78✔
115
            caching === "database"
78✔
116
        )
78✔
117
            return {
78!
118
                type: caching,
×
119
                options: PlatformTools.getEnvVariable("TYPEORM_CACHE_OPTIONS")
×
120
                    ? JSON.parse(
×
121
                          PlatformTools.getEnvVariable("TYPEORM_CACHE_OPTIONS"),
×
122
                      )
×
123
                    : undefined,
×
124
                alwaysEnabled: PlatformTools.getEnvVariable(
×
125
                    "TYPEORM_CACHE_ALWAYS_ENABLED",
×
126
                ),
×
127
                duration: parseInt(
×
128
                    PlatformTools.getEnvVariable("TYPEORM_CACHE_DURATION"),
×
129
                ),
×
130
            }
×
131

78✔
132
        return undefined
78✔
133
    }
78✔
134

26✔
135
    /**
26✔
136
     * Converts a string which contains multiple elements split by comma into a string array of strings.
26✔
137
     */
26✔
138
    protected stringToArray(variable?: string) {
26✔
139
        if (!variable) return []
312✔
140
        return variable.split(",").map((str) => str.trim())
×
141
    }
×
142

26✔
143
    /**
26✔
144
     * Converts a string which contains a number into a javascript number
26✔
145
     */
26✔
146
    private stringToNumber(value: any): number | undefined {
26✔
147
        if (!value) {
78✔
148
            return undefined
78✔
149
        }
78✔
150

×
151
        return parseInt(value)
×
152
    }
×
153
}
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