connection static method
Gets a Database connection instance.
connection
Optional, the connection instance to obtain based on the
connections list in your database.dart config.
Implementation
static DBConnection? connection([String? connection]) {
if (_mainInstance?._core == null) {
throw ComponentNotBootedException('Database system not booted.');
}
if (connection == null) {
return _mainInstance!._dbConnection;
}
if (_instances.keys.contains(connection)) {
return _instances[connection]!._dbConnection;
}
final instance = DB._();
if (!_mainInstance!._core!.configMap[_ConfigKeys.connections].keys
.contains(connection)) {
throw DBConnectionNotFoundException(connection);
}
instance._dbConnection = DBConnection(_mainInstance!._core!
.configMap[_ConfigKeys.connections][connection] as DatabaseConnection);
_instances[connection] = instance;
return instance._dbConnection;
}