begin static method

Future<DBAccess> begin()

Starts an transactions. You don't need to call this method if you're using access.

If you prefer to handle the transaction explicitly, you MUST do as follows.

final access = await DBAccess.begin();
try {
   ...
} catch (ex) {
  access.rollingback = true;
  //rethrow or handle it
} finally {
  await access.close();
}

Implementation

static Future<DBAccess> begin() async {
  DBAccess? access;
  ++_nAccess; //increase first, so [currentAccessCount] more accurate
  try {
    access = DBAccess._(await _pool!.connect());
    await access._begin();
    access._beginCounted = true;
    return access;
  } catch (ex) {
    access?._close(ex); //never throws an exception
    --_nAccess;
    rethrow;
  }
}