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

typeorm / typeorm / 14796576772

02 May 2025 01:52PM UTC coverage: 45.367% (-30.9%) from 76.309%
14796576772

Pull #11434

github

web-flow
Merge ec4ce2d00 into fadad1a74
Pull Request #11434: feat: release PR releases using pkg.pr.new

5216 of 12761 branches covered (40.87%)

Branch coverage included in aggregate %.

11439 of 23951 relevant lines covered (47.76%)

15712.55 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"
4✔
2
import { ConnectionNotFoundError } from "../error/ConnectionNotFoundError"
4✔
3
import { DataSourceOptions } from "../data-source/DataSourceOptions"
4
import { AlreadyHasActiveConnectionError } from "../error/AlreadyHasActiveConnectionError"
4✔
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 {
4✔
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
     */
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 {
×
42
        const connection = this.connectionMap.get(name)
×
43
        if (!connection) throw new ConnectionNotFoundError(name)
×
44

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
54
        const existConnection = this.connectionMap.get(
×
55
            options.name || "default",
×
56
        )
57
        if (existConnection) {
×
58
            // if connection is registered and its not closed then throw an error
59
            if (existConnection.isInitialized)
×
60
                throw new AlreadyHasActiveConnectionError(
×
61
                    options.name || "default",
×
62
                )
63
        }
64

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