@fxjs/db-driver
Version:
[](https://www.npmjs.org/package/@fxjs/db-driver) [](https://travis-ci.org/fxjs-modules/db-driver) [ • 1.39 kB
JavaScript
/// <reference types="fib-pool" />
Object.defineProperty(exports, "__esModule", { value: true });
const db = require("db");
const base_class_1 = require("./base.class");
class MongoDriver extends base_class_1.Driver {
constructor(conn) {
super(conn);
this.connection = null;
}
switchDb(targetDb) {
if (!this.connection)
this.open();
const currentDb = this.connection.getName();
if (currentDb === targetDb)
return;
this.connection.getSiblingDB(targetDb);
}
reopen() {
try {
this.close();
}
catch (error) { }
return this.open();
}
open() {
return super.open();
}
close() {
if (this.connection)
this.connection.close();
this.connection = null;
}
ping() { }
command(cmd, arg) {
return this.commands({ [cmd]: arg });
}
commands(cmds, opts) {
if (this.isPool)
return this.pool(conn => conn.runCommand(cmds));
if (!this.connection)
this.open();
return this.connection.runCommand(cmds);
}
getConnection() {
// @notice it's invalid cast, you should replace one JS implementation of mongodb
return db.openMongoDB(this.uri);
}
}
exports.default = MongoDriver;