tableExists static method
Check if a table exists.
Implementation
static Future<bool> tableExists(String tableName) async {
await _ensureConnected();
try {
if (_driver == DBDriver.postgres) {
final result = await query(
"SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_name = :table)",
namedParams: {'table': tableName},
);
return result.first['exists'] as bool;
} else {
final result = await query(
"SELECT COUNT(*) as count FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = ?",
positionalParams: [tableName],
);
final count = result.first['count'];
if (count is String) return int.parse(count) > 0;
if (count is int) return count > 0;
if (count is BigInt) return count > BigInt.zero;
return (count as num) > 0;
}
} catch (_) {
return false;
}
}