1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.ConnectionManager = void 0;
|
4 | const connection_1 = require("./connection");
|
5 | class ConnectionManager {
|
6 | constructor() {
|
7 | this.default = "main";
|
8 | this.connections = {};
|
9 | }
|
10 | connect(host, name = "main") {
|
11 | if (this.connections[name]) {
|
12 | throw new Error(`Connection [${name}] is already configured.`);
|
13 | }
|
14 | this.connections[name] = new connection_1.Connection(host);
|
15 | return this.connections[name];
|
16 | }
|
17 | disconnect(name) {
|
18 | name = name || this.getDefaultConnection();
|
19 | delete this.connections[name];
|
20 | }
|
21 | connection(name) {
|
22 | name = name || this.getDefaultConnection();
|
23 | if (!this.connections[name]) {
|
24 | throw new Error(`Connection [${name}] not configured.`);
|
25 | }
|
26 | return this.connections[name];
|
27 | }
|
28 | getDefaultConnection() {
|
29 | return this.default;
|
30 | }
|
31 | setDefaultConnection(name) {
|
32 | this.default = name;
|
33 | }
|
34 | getConnections() {
|
35 | return this.connections;
|
36 | }
|
37 | }
|
38 | exports.ConnectionManager = ConnectionManager;
|
39 |
|
\ | No newline at end of file |