diff --git a/package.json b/package.json index 6353939..23027f5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "quickmongo", - "version": "5.0.1", + "version": "5.1.0", "description": "Quick Mongodb wrapper for beginners that provides key-value based interface.", "main": "dist/index.js", "module": "dist/index.mjs", diff --git a/src/Database.ts b/src/Database.ts index 3f5ad8a..b4828f0 100644 --- a/src/Database.ts +++ b/src/Database.ts @@ -66,7 +66,6 @@ interface QmEvents { fullsetup: () => unknown; all: () => unknown; reconnectFailed: () => unknown; - reconnectTries: () => unknown; } /** @@ -297,7 +296,7 @@ export class Database extends TypedEmitter} @@ -317,6 +316,45 @@ export class Database extends TypedEmitter { + const name = args[0]; + if (!name || typeof name !== "string") throw new TypeError("ERR_TABLE_NAME"); + const db = new Database(this.url, this.options); + + db.connection = this.connection; + db.model = modelSchema(this.connection, name); + db.connect = () => Promise.resolve(db); + + Object.defineProperty(db, "table", { + get() { + return; + }, + set() { + return; + } + }); + + return db; + }, + apply: () => { + throw new Error("TABLE_IS_NOT_A_FUNCTION"); + } + } + ); + } + /** * Returns everything from the database * @param {?AllQueryOptions} options The request options @@ -523,6 +561,10 @@ export class Database extends TypedEmitter { + new (name: string): Database; +} + /** * Emitted once the database is ready * @event Database#ready