getEnvironmentStats method

Future<DatabaseStats> getEnvironmentStats()

Gets environment-wide statistics

Returns statistics for the entire LMDB environment

Throws StateError if database is closed Throws LMDBException if operation fails

Implementation

Future<DatabaseStats> getEnvironmentStats() async {
  if (!isInitialized) throw StateError(_errDbNotInitialized);

  final statPtr = calloc<MDB_stat>();
  try {
    final result = _lib.mdb_env_stat(
      env,
      statPtr,
    );

    if (result != 0) {
      throw LMDBException('Failed to get environment statistics', result);
    }

    return DatabaseStats(
      pageSize: statPtr.ref.ms_psize,
      depth: statPtr.ref.ms_depth,
      branchPages: statPtr.ref.ms_branch_pages,
      leafPages: statPtr.ref.ms_leaf_pages,
      overflowPages: statPtr.ref.ms_overflow_pages,
      entries: statPtr.ref.ms_entries,
    );
  } finally {
    calloc.free(statPtr);
  }
}