@adonisjs/lucid
Version:
SQL ORM built on top of Active Record pattern
61 lines (60 loc) • 1.65 kB
JavaScript
/*
* @adonisjs/lucid
*
* (c) AdonisJS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { BaseCheck, Result } from '@adonisjs/core/health';
/**
* The DbCheck attempts to establish the database connection by
* executing a sample query.
*/
export class DbCheck extends BaseCheck {
/**
* Health check public name
*/
name;
constructor(client) {
super();
this.
this.name = `Database health check (${client.connectionName})`;
}
/**
* Returns connection metadata to be shared in the health checks
* report
*/
return {
connection: {
name: this.
dialect: this.
},
};
}
/**
* Internal method to ping the database server
*/
async
if (this.
await this.
}
else {
await this.
}
}
/**
* Executes the health check
*/
async run() {
try {
await this.
return Result.ok('Successfully connected to the database server').mergeMetaData(this.
}
catch (error) {
return Result.failed(error.message || 'Connection failed', error).mergeMetaData(this.
}
}
}