UNPKG

3.15 kBTypeScriptView Raw
1/// <reference path="../../adonis-typings/index.d.ts" />
2/// <reference types="@adonisjs/logger/build/adonis-typings/logger" />
3/// <reference types="@adonisjs/events/build/adonis-typings" />
4import { EmitterContract } from '@ioc:Adonis/Core/Event';
5import { LoggerContract } from '@ioc:Adonis/Core/Logger';
6import { HealthReportEntry } from '@ioc:Adonis/Core/HealthCheck';
7import { ReportNode, ConnectionNode, ConnectionConfig, ConnectionManagerContract } from '@ioc:Adonis/Lucid/Database';
8/**
9 * Connection manager job is to manage multiple named connections. You can add any number
10 * or connections by registering their config only once and then make use of `connect`
11 * and `close` methods to create and destroy db connections.
12 */
13export declare class ConnectionManager implements ConnectionManagerContract {
14 private logger;
15 private emitter;
16 /**
17 * List of managed connections
18 */
19 connections: ConnectionManagerContract['connections'];
20 /**
21 * Connections for which the config was patched. They must get removed
22 * overtime, unless application is behaving unstable.
23 */
24 private orphanConnections;
25 constructor(logger: LoggerContract, emitter: EmitterContract);
26 /**
27 * Handles disconnection of a connection
28 */
29 private handleDisconnect;
30 /**
31 * Handles event when a new connection is added
32 */
33 private handleConnect;
34 /**
35 * Monitors a given connection by listening for lifecycle events
36 */
37 private monitorConnection;
38 /**
39 * Add a named connection with it's configuration. Make sure to call `connect`
40 * before using the connection to make database queries.
41 */
42 add(connectionName: string, config: ConnectionConfig): void;
43 /**
44 * Connect to the database using config for a given named connection
45 */
46 connect(connectionName: string): void;
47 /**
48 * Patching the config
49 */
50 patch(connectionName: string, config: ConnectionConfig): void;
51 /**
52 * Returns the connection node for a given named connection
53 */
54 get(connectionName: string): ConnectionNode | undefined;
55 /**
56 * Returns a boolean telling if we have connection details for
57 * a given named connection. This method doesn't tell if
58 * connection is connected or not.
59 */
60 has(connectionName: string): boolean;
61 /**
62 * Returns a boolean telling if connection has been established
63 * with the database or not
64 */
65 isConnected(connectionName: string): boolean;
66 /**
67 * Closes a given connection and can optionally release it from the
68 * tracking list
69 */
70 close(connectionName: string, release?: boolean): Promise<void>;
71 /**
72 * Close all tracked connections
73 */
74 closeAll(release?: boolean): Promise<void>;
75 /**
76 * Release a connection. This will disconnect the connection
77 * and will delete it from internal list
78 */
79 release(connectionName: string): Promise<void>;
80 /**
81 * Returns the report for all the connections marked for healthChecks.
82 */
83 report(): Promise<HealthReportEntry & {
84 meta: ReportNode[];
85 }>;
86}