tona-db-mini
Version:
Tona-DB mini is a JavaScript library for simulating small local databases in JSON.
38 lines (37 loc) • 1.32 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MiniDB = void 0;
const fs_1 = __importDefault(require("fs"));
const loader_1 = require("../config/loader");
const merger_1 = require("../config/merger");
const collection_1 = require("./collection");
/**
* Main entry point to access collections.
* Automatically loads user configuration and handles base directory setup.
*/
class MiniDB {
config;
/**
* Main entry point to access collections.
* Automatically loads user configuration and handles base directory setup.
* @param config Configuration options
*/
constructor(config = {}) {
this.config = (0, merger_1.mergeDefaultConfig)({ ...(0, loader_1.loadConfig)(), ...config });
if (!fs_1.default.existsSync(this.config.baseDir)) {
fs_1.default.mkdirSync(this.config.baseDir, { recursive: true });
}
}
/**
* Returns a typed collection by name.
* @param name Name of the collection
* @returns {Collection<T>} The collection
*/
collection(name) {
return new collection_1.Collection(name, this.config);
}
}
exports.MiniDB = MiniDB;