smartdata/dist/smartdata.classes.db.js

76 lines
4.9 KiB
JavaScript
Raw Normal View History

2017-07-15 22:11:03 +00:00
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./smartdata.plugins");
const lik_1 = require("lik");
class Db {
constructor(connectionOptionsArg) {
this.dbTablesMap = new lik_1.Objectmap();
this.dbName = connectionOptionsArg.db;
this.connectionOptions = connectionOptionsArg;
this.status = "initial";
2017-07-15 22:11:03 +00:00
}
/**
* supply additional SSl options needed to connect to certain Rethink DB servers (e.g. compose.io)
*/
setSsl(certificateStringArg, formatArg) {
let certificateString;
if ((formatArg = "base64")) {
certificateString = plugins.smartstring.base64.decode(certificateStringArg);
}
else {
certificateString = certificateStringArg;
}
this.connectionOptions["ssl"] = {
ca: Buffer.from(certificateString)
};
}
2017-07-15 22:11:03 +00:00
// basic connection stuff ----------------------------------------------
/**
* connects to the database that was specified during instance creation
*/
connect() {
2018-01-07 16:26:34 +00:00
return __awaiter(this, void 0, void 0, function* () {
this.dbConnection = yield plugins.rethinkDb.connect(this.connectionOptions);
this.dbConnection.use(this.dbName);
this.status = "connected";
plugins.beautylog.ok(`Connected to database ${this.dbName}`);
2017-07-15 22:11:03 +00:00
});
}
/**
* closes the connection to the databse
*/
close() {
return __awaiter(this, void 0, void 0, function* () {
yield this.dbConnection.close();
this.status = "disconnected";
plugins.beautylog.ok(`disconnected from database ${this.dbName}`);
2017-07-15 22:11:03 +00:00
});
}
// handle table to class distribution
addTable(dbTableArg) {
this.dbTablesMap.add(dbTableArg);
}
2017-07-15 22:11:03 +00:00
/**
* Gets a table's name and returns smartdata's DbTable class
* @param nameArg
* @returns DbTable
2017-07-15 22:11:03 +00:00
*/
getDbTableByName(nameArg) {
2017-07-15 22:11:03 +00:00
return __awaiter(this, void 0, void 0, function* () {
let resultCollection = this.dbTablesMap.find(dbTableArg => {
return dbTableArg.tableName === nameArg;
2017-07-15 22:11:03 +00:00
});
return resultCollection;
2017-07-15 22:11:03 +00:00
});
}
}
exports.Db = Db;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRhdGEuY2xhc3Nlcy5kYi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsK0NBQStDO0FBQy9DLDZCQUFnQztBQWVoQztJQU9FLFlBQVksb0JBQXVDO1FBRm5ELGdCQUFXLEdBQUcsSUFBSSxlQUFTLEVBQWdCLENBQUM7UUFHMUMsSUFBSSxDQUFDLE1BQU0sR0FBRyxvQkFBb0IsQ0FBQyxFQUFFLENBQUM7UUFDdEMsSUFBSSxDQUFDLGlCQUFpQixHQUFHLG9CQUFvQixDQUFDO1FBQzlDLElBQUksQ0FBQyxNQUFNLEdBQUcsU0FBUyxDQUFDO0lBQzFCLENBQUM7SUFFRDs7T0FFRztJQUNILE1BQU0sQ0FBQyxvQkFBNEIsRUFBRSxTQUFpQztRQUNwRSxJQUFJLGlCQUF5QixDQUFDO1FBQzlCLEVBQUUsQ0FBQyxDQUFDLENBQUMsU0FBUyxHQUFHLFFBQVEsQ0FBQyxDQUFDLENBQUMsQ0FBQztZQUMzQixpQkFBaUIsR0FBRyxPQUFPLENBQUMsV0FBVyxDQUFDLE1BQU0sQ0FBQyxNQUFNLENBQ25ELG9CQUFvQixDQUNyQixDQUFDO1FBQ0osQ0FBQztRQUFDLElBQUksQ0FBQyxDQUFDO1lBQ04sa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