smartdata/dist/smartdata.classes.db.js

60 lines
3.8 KiB
JavaScript

"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';
}
// basic connection stuff ----------------------------------------------
/**
* connects to the database that was specified during instance creation
*/
connect() {
return __awaiter(this, void 0, void 0, function* () {
this.dbConnection = yield plugins.rethinkDb.connect(this.connectionOptions);
this.status = 'connected';
plugins.beautylog.ok(`Connected to database ${this.dbName}`);
});
}
/**
* 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 to database ${this.dbName}`);
});
}
// handle table to class distribution
/**
* Gets a table's name and returns smartdata's DbTable class
* @param nameArg
* @returns DbTable
*/
getDbTableByName(nameArg) {
return __awaiter(this, void 0, void 0, function* () {
let resultCollection = this.dbTablesMap.find((dbCollectionArg) => {
return dbCollectionArg.name === nameArg;
});
return resultCollection;
});
}
addTable(dbCollectionArg) {
this.dbTablesMap.add(dbCollectionArg);
}
}
exports.Db = Db;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRhdGEuY2xhc3Nlcy5kYi50cyJdLCJuY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