• 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

89.61
/src/connection/ConnectionManager.ts
1
import { DataSource } from "../data-source/DataSource"
26✔
2
import { ConnectionNotFoundError } from "../error/ConnectionNotFoundError"
26✔
3
import { DataSourceOptions } from "../data-source/DataSourceOptions"
26✔
4
import { AlreadyHasActiveConnectionError } from "../error/AlreadyHasActiveConnectionError"
26✔
5

26✔
6
/**
26✔
7
 * ConnectionManager is used to store and manage multiple orm connections.
26✔
8
 * It also provides useful factory methods to simplify connection creation.
26✔
9
 *
26✔
10
 * @deprecated
26✔
11
 */
26✔
12
export class ConnectionManager {
20✔
13
    /**
20✔
14
     * List of connections registered in this connection manager.
20✔
15
     */
20✔
16
    get connections(): DataSource[] {
20✔
17
        return Array.from(this.connectionMap.values())
×
18
    }
×
19

20✔
20
    /**
20✔
21
     * Internal lookup to quickly get from a connection name to the Connection object.
20✔
22
     */
20✔
23
    private readonly connectionMap: Map<string, DataSource> = new Map()
20✔
24

20✔
25
    // -------------------------------------------------------------------------
20✔
26
    // Public Methods
20✔
27
    // -------------------------------------------------------------------------
20✔
28

20✔
29
    /**
20✔
30
     * Checks if connection with the given name exist in the manager.
20✔
31
     */
20✔
32
    has(name: string): boolean {
20✔
33
        return this.connectionMap.has(name)
×
34
    }
×
35

20✔
36
    /**
20✔
37
     * Gets registered connection with the given name.
20✔
38
     * If connection name is not given then it will get a default connection.
20✔
39
     * Throws error if connection with the given name was not found.
20✔
40
     */
20✔
41
    get(name: string = "default"): DataSource {
20✔
42
        const connection = this.connectionMap.get(name)
8✔
43
        if (!connection) throw new ConnectionNotFoundError(name)
8✔
44

4✔
45
        return connection
4✔
46
    }
4✔
47

20✔
48
    /**
20✔
49
     * Creates a new connection based on the given connection options and registers it in the manager.
20✔
50
     * Connection won't be established, you'll need to manually call connect method to establish connection.
20✔
51
     */
20✔
52
    create(options: DataSourceOptions): DataSource {
20✔
53
        // check if such connection is already registered
28✔
54
        const existConnection = this.connectionMap.get(
28✔
55
            options.name || "default",
28!
56
        )
28✔
57
        if (existConnection) {
28✔
58
            // if connection is registered and its not closed then throw an error
8✔
59
            if (existConnection.isInitialized)
8✔
60
                throw new AlreadyHasActiveConnectionError(
8!
61
                    options.name || "default",
×
62
                )
×
63
        }
8✔
64

28✔
65
        // create a new connection
28✔
66
        const connection = new DataSource(options)
28✔
67
        this.connectionMap.set(connection.name, connection)
28✔
68
        return connection
28✔
69
    }
28✔
70
}
20✔
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