moonlifedb
Version:
A JSON database with a bunch of tools and typescript support.
70 lines (69 loc) • 2.77 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TableCreator = void 0;
const fs = __importStar(require("fs"));
const CoreCheck_1 = require("./CoreCheck");
const ExternalConnection_1 = require("./adapters/ExternalConnection");
const lib = new CoreCheck_1.Memory();
class TableCreator {
adapter;
useTabulation;
tablePath;
ip;
port;
/**
* NOT SUPPORTED YET
*
* The class to work with tables
* @example const creator = new TableCreator(adapter);
* @param adapter
*/
constructor(adapter, options) {
this.adapter = adapter;
this.tablePath = this.adapter.tablePath;
if (this.adapter instanceof ExternalConnection_1.ExternalConnection) {
this.ip = this.adapter.localip;
this.port = this.adapter.port;
}
options && options.useTabulation
? this.useTabulation = options.useTabulation
: this.useTabulation = undefined;
lib.checkDir(this.tablePath);
}
/**
* NOT SUPPORTED YET
*/
create(name, settings) {
lib.checkDir(this.tablePath);
let result = {};
if (fs.existsSync(this.tablePath + '/' + name + '.json'))
console.log('Alert: already exists in the database: overwritten');
fs.writeFileSync(this.tablePath + '/' + name + '.json', JSON.stringify(result));
if (settings && settings.strict)
fs.writeFileSync(this.tablePath + '/' + name + '-structure.json', JSON.stringify(settings.strict, null, this.useTabulation == undefined ? '\t' : this.useTabulation.whitespace));
}
}
exports.TableCreator = TableCreator;