Skip to content

Commit

Permalink
feat(command): wait for connection in mongodriver
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Nov 18, 2024
1 parent 9b5a3a0 commit 5d627b9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/database",
"version": "4.62.0",
"version": "4.63.0",
"description": "The Athenna database handler for SQL/NoSQL.",
"license": "MIT",
"author": "João Lenon <[email protected]>",
Expand Down
17 changes: 17 additions & 0 deletions src/commands/DbSeedCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* file that was distributed with this source code.
*/

import { Exec } from '@athenna/common'
import { Database } from '#src/facades/Database'
import { BaseCommand, Option } from '@athenna/artisan'

Expand Down Expand Up @@ -37,6 +38,11 @@ export class DbSeedCommand extends BaseCommand {
this.logger.simple('({bold,green} [ SEEDING DATABASE ])\n')

const DB = Database.connection(this.connection)

if (this.getConfig('driver') === 'mongo') {
await Exec.sleep(1000)
}

const task = this.logger.task()
const dbName = await DB.getCurrentDatabase()

Expand All @@ -47,4 +53,15 @@ export class DbSeedCommand extends BaseCommand {
console.log()
this.logger.success(`Database ({yellow} "${dbName}") successfully seeded.`)
}

private getConfig(name: string, defaultValue?: any) {
return Config.get(
`database.connections.${
this.connection === 'default'
? Config.get('database.default')
: this.connection
}.${name}`,
defaultValue
)
}
}
8 changes: 7 additions & 1 deletion src/commands/DbWipeCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export class DbWipeCommand extends BaseCommand {
const task = this.logger.task()

if (this.getConfig('driver') === 'mongo') {
await Exec.sleep(1000)

const tables = await DB.getTables()

task.addPromise('Dropping all database tables', () => {
Expand Down Expand Up @@ -61,7 +63,11 @@ export class DbWipeCommand extends BaseCommand {

private getConfig(name: string, defaultValue?: any) {
return Config.get(
`database.connections.${this.connection}.${name}`,
`database.connections.${
this.connection === 'default'
? Config.get('database.default')
: this.connection
}.${name}`,
defaultValue
)
}
Expand Down

0 comments on commit 5d627b9

Please sign in to comment.