cursorCount method

Future<int> cursorCount(
  1. Pointer<MDB_txn> txn, {
  2. String? dbName,
})

Helper method to count entries using a cursor

Parameters:

  • txn - Active transaction
  • dbName - Optional named database

Returns the number of entries in the database

Example:

final count = await db.cursorCount();
print('Database contains $count entries');

Implementation

Future<int> cursorCount(
  Pointer<MDB_txn> txn, {
  String? dbName,
}) async {
  final cursor = await cursorOpen(txn, dbName: dbName);
  try {
    var count = 0;
    var entry = await cursorGet(cursor, null, CursorOp.first);
    while (entry != null) {
      count++;
      entry = await cursorGet(cursor, null, CursorOp.next);
    }
    return count;
  } finally {
    cursorClose(cursor);
  }
}