setup method
Implementation
@override
Future<void> setup(Map<String, dynamic> databaseConfig) async {
final driver = databaseConfig['default'];
if (driver is! String || driver.isEmpty) {
throw DatabaseException(
'A database must be specified: "default" is missing from the '
'database config.',
);
}
final connections = databaseConfig['connections'];
if (connections is! Map<String, dynamic> || connections[driver] == null) {
throw DatabaseException(
'Database config not valid: no connection named "$driver"',
);
}
try {
final connectionManager = ConnectionManager();
connectionManager.defaultConnection = driver;
_driver = driver;
await connectionManager.connect(
_createDBConfig(connections[driver]),
driver,
);
final connection = connectionManager.connection(driver);
if (connection == null) {
throw DatabaseException('Failed to open a connection for "$driver"');
}
_dbConnection = connection;
_adapter = _createAdapter(driver);
await connection.execute(_adapter!.getMigrationsTableSql());
} on InvalidArgumentException catch (e) {
throw DatabaseException(e.message);
}
}