connect static method
Manual connect for dynamic tenant switching.
Implementation
static Future<void> connect({
required String database,
String? host,
int? port,
String? username,
String? password,
bool? isSecure,
}) async {
_isConnected = false;
final driver = FlintEnv.get('DB_CONNECTION', 'mysql');
if (driver == 'postgres') {
_driver = DBDriver.postgres;
_pg = PgConnectionWrapper();
await _pg!.connect(
host: host ?? FlintEnv.get('DB_HOST', 'localhost'),
port: port ?? FlintEnv.getInt('DB_PORT', 5432),
database: database,
username: username ?? FlintEnv.get('DB_USER', 'postgres'),
password: password ?? FlintEnv.get('DB_PASSWORD', ''),
);
} else {
_driver = DBDriver.mysql;
_mysql = MySqlConnectionWrapper();
await _mysql!.connect(
host: host ?? FlintEnv.get('DB_HOST', 'localhost'),
port: port ?? FlintEnv.getInt('DB_PORT', 3306),
db: database,
user: username ?? FlintEnv.get('DB_USER', 'root'),
password: password ?? FlintEnv.get('DB_PASSWORD', ''),
isSecure: isSecure ?? FlintEnv.getBool('DB_SECURE', false),
);
}
_isConnected = true;
}