connectMysqlDb method
Connects to MySQL using the connection string from the configuration.
Implementation
Future<void> connectMysqlDb() async {
if (config.mysqlConfig.enable) {
_mysqlDb = await MySQLConnection.createConnection(
host: config.mysqlConfig.host,
port: config.mysqlConfig.port,
userName: config.mysqlConfig.user,
password: config.mysqlConfig.pass,
databaseName: config.mysqlConfig.databaseName,
secure: config.mysqlConfig.secure,
collation: config.mysqlConfig.collation,
);
_mysqlDb!.onClose(
() => Console.e("MySQL connection closed"),
);
if (config.mysqlConfig.enable) {
await _mysqlDb!.connect().onError((err, stack) {
Console.e(err.toString());
});
}
}
}