open method

  1. @override
Future<bool> open({
  1. Function? populateFunction,
  2. int timeoutInSeconds = 30,
  3. int queryTimeoutInSeconds = 30,
  4. String timeZone = 'UTC',
  5. bool useSSL = false,
  6. bool isUnixSocket = false,
  7. bool allowClearTextPassword = false,
})
override

Open the database and returns true upon success.

If supplied the populateFunction is used.

For sqlite this happens if the db didn't exist, while for postgres the function is executed no matter what, if available.

Implementation

@override
Future<bool> open({
  Function? populateFunction,
  int timeoutInSeconds = 30,
  int queryTimeoutInSeconds = 30,
  String timeZone = 'UTC',
  bool useSSL = false,
  bool isUnixSocket = false,
  bool allowClearTextPassword = false,
}) async {
  try {
    if (_db != null) {
      throw StateError("Database already opened.");
    }
    _db = PostgreSQLConnection(
      _host,
      port,
      _dbName,
      username: user,
      password: pwd,
      timeoutInSeconds: timeoutInSeconds,
      queryTimeoutInSeconds: queryTimeoutInSeconds,
      timeZone: timeZone,
      useSSL: useSSL,
      isUnixSocket: isUnixSocket,
      allowClearTextPassword: allowClearTextPassword,
    );
    await _db?.open();

    if (populateFunction != null) {
      await populateFunction(this);
    }
    return true;
  } on Exception {
    _db = null;
    rethrow;
    // return false;
  }
}