ping method
Returns true when the database answers a trivial query within
timeout, false otherwise — never throws.
Designed for health checks:
app.enableHealthCheck(checks: [
() async => HealthCheckResult(name: 'database', healthy: await db.ping()),
]);
Implementation
@override
Future<bool> ping({Duration timeout = const Duration(seconds: 2)}) async {
try {
await rawQuery('SELECT 1;').timeout(timeout);
return true;
} catch (_) {
return false;
}
}