1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const Database_1 = require("./Database");
|
4 | const MySQLConnection_1 = require("./MySQLConnection");
|
5 | const MySQL = require("mysql");
|
6 | const instance_1 = require("./instance");
|
7 | class MySQLDatabase extends Database_1.Database {
|
8 | constructor() {
|
9 | super();
|
10 | this.cluster = MySQL.createPoolCluster();
|
11 | }
|
12 | escape(query) {
|
13 | return MySQL.escape(query);
|
14 | }
|
15 | _addNode(nodeID, config) {
|
16 | instance_1.getApplicationLogger().trace(`Adding node to connection pool: "${nodeID}"`);
|
17 | this.cluster.add(nodeID, config);
|
18 | }
|
19 | _removeNode(nodeID) {
|
20 | instance_1.getApplicationLogger().trace(`Removing node to connection pool: "${nodeID}"`);
|
21 | this.cluster.remove(nodeID);
|
22 | }
|
23 | _getConnection(query, requireWriteAccess) {
|
24 | instance_1.getApplicationLogger().trace(`Querying connection pool for "${query}".`);
|
25 | return new Promise((resolve, reject) => {
|
26 | let instantationStack = new Error().stack;
|
27 | this.cluster.getConnection(query, (error, connection) => {
|
28 | if (error) {
|
29 | reject(error);
|
30 | return;
|
31 | }
|
32 | resolve(new MySQLConnection_1.MySQLConnection(connection, instantationStack, !requireWriteAccess));
|
33 | });
|
34 | });
|
35 | }
|
36 | }
|
37 | exports.MySQLDatabase = MySQLDatabase;
|
38 |
|
\ | No newline at end of file |