connect method

  1. @override
Future<AnySqlConnection> connect(
  1. AnySqlConfig config
)
override

Opens a new database connection.

Implementation

@override
Future<AnySqlConnection> connect(AnySqlConfig config) async {
  checkSupported(config);

  try {
    final connection = await pg.Connection.open(
      pg.Endpoint(
        host: config.host!,
        port: config.port ?? 5432,
        database: config.database!,
        username: config.username,
        password: config.password,
      ),
      settings: pg.ConnectionSettings(
        sslMode: config.sslEnabled ? pg.SslMode.require : pg.SslMode.disable,
      ),
    );

    return PostgresAnySqlConnection(connection);
  } on Object catch (error) {
    throw AnySqlException('Failed to connect to PostgreSQL.', error);
  }
}