From 35e03e103cb65c1eaa8f4b3f1866fe3afbfbe414 Mon Sep 17 00:00:00 2001 From: jlenon7 Date: Wed, 20 Nov 2024 14:39:53 +0000 Subject: [PATCH] feat(command): wait for connection to be stablished --- package-lock.json | 4 ++-- package.json | 2 +- src/commands/DbSeedCommand.ts | 18 +++++++++++------- src/commands/DbWipeCommand.ts | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index afb87fa..2644c4e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/database", - "version": "5.5.0", + "version": "5.6.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@athenna/database", - "version": "5.5.0", + "version": "5.6.0", "license": "MIT", "dependencies": { "@faker-js/faker": "^8.4.1", diff --git a/package.json b/package.json index 33db5d1..b297a20 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/database", - "version": "5.5.0", + "version": "5.6.0", "description": "The Athenna database handler for SQL/NoSQL.", "license": "MIT", "author": "João Lenon ", diff --git a/src/commands/DbSeedCommand.ts b/src/commands/DbSeedCommand.ts index 2d37cf7..8e1339b 100644 --- a/src/commands/DbSeedCommand.ts +++ b/src/commands/DbSeedCommand.ts @@ -41,19 +41,23 @@ export class DbSeedCommand extends BaseCommand { const DB = Database.connection(this.connection) if (this.getConfig('driver') === 'mongo') { - task.addPromise('Connecting to database', async () => { - await Exec.sleep(5000) + task.addPromise('Connecting to database', () => { + return Exec.sleep(5000) }) } - const dbName = await DB.getCurrentDatabase() - await DB.runSeeders({ task, classes: this.classes }) - await task.run().finally(() => DB.close()) + await task.run().finally(async () => { + const dbName = await DB.getCurrentDatabase() + + await DB.close() - console.log() - this.logger.success(`Database ({yellow} "${dbName}") successfully seeded.`) + console.log() + this.logger.success( + `Database ({yellow} "${dbName}") successfully seeded.` + ) + }) } private getConfig(name: string, defaultValue?: any) { diff --git a/src/commands/DbWipeCommand.ts b/src/commands/DbWipeCommand.ts index 014f40a..d7354bd 100644 --- a/src/commands/DbWipeCommand.ts +++ b/src/commands/DbWipeCommand.ts @@ -30,8 +30,8 @@ export class DbWipeCommand extends BaseCommand { public async handle(): Promise { this.logger.simple('({bold,green} [ WIPING DATABASE ])\n') - const DB = Database.connection(this.connection) const task = this.logger.task() + const DB = Database.connection(this.connection) if (this.getConfig('driver') === 'mongo') { task.addPromise('Connecting to database', () => {