MCPcopy
hub / github.com/directus/directus / validateDatabaseConnection

Function validateDatabaseConnection

api/src/database/index.ts:236–251  ·  view source on GitHub ↗
(database?: Knex)

Source from the content-addressed store, hash-verified

234}
235
236export async function validateDatabaseConnection(database?: Knex): Promise<void> {
237 database = database ?? getDatabase();
238 const logger = useLogger();
239
240 try {
241 if (getDatabaseClient(database) === 'oracle') {
242 await database.raw('select 1 from DUAL');
243 } else {
244 await database.raw('SELECT 1');
245 }
246 } catch (error: any) {
247 logger.error(`Can't connect to the database.`);
248 logger.error(error);
249 process.exit(1);
250 }
251}
252
253export function getDatabaseClient(database?: Knex): DatabaseClient {
254 database = database ?? getDatabase();

Callers 3

createAppFunction · 0.85
applyFunction · 0.85
waitForDatabaseFunction · 0.85

Calls 3

getDatabaseFunction · 0.85
useLoggerFunction · 0.85
getDatabaseClientFunction · 0.70

Tested by

no test coverage detected