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

typeorm / typeorm / 15219332477

23 May 2025 09:13PM UTC coverage: 17.216% (-59.1%) from 76.346%
15219332477

Pull #11332

github

naorpeled
cr comments - move if block
Pull Request #11332: feat: add new undefined and null behavior flags

1603 of 12759 branches covered (12.56%)

Branch coverage included in aggregate %.

0 of 31 new or added lines in 3 files covered. (0.0%)

14132 existing lines in 166 files now uncovered.

4731 of 24033 relevant lines covered (19.69%)

60.22 hits per line

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

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

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

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

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

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

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

UNCOV
45
        return connection
×
46
    }
47

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

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

© 2025 Coveralls, Inc