connect static method

Future<void> connect({
  1. required String database,
  2. String? host,
  3. int? port,
  4. String? username,
  5. String? password,
  6. bool? isSecure,
})

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;
}