connection method
Gets the current connection.
Implementation
DatabaseConnection connection([String? name]) {
final connectionName = name ?? _config.get('database.default', 'mysql')!;
if (!_pools.containsKey(connectionName)) {
_initializePool(connectionName);
}
final pool = _pools[connectionName]!;
if (pool.length == 1) {
return pool.first;
}
final currentIndex = _poolIndexes[connectionName] ?? 0;
final selected = pool[currentIndex % pool.length];
_poolIndexes[connectionName] = (currentIndex + 1) % pool.length;
return selected;
}