Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a method to list all boxes #1230

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add a method to list all boxes
Louis-Navarro committed Aug 10, 2023
commit a0ea739b99818efb6e20e528dc0e24afbcad12ce
4 changes: 3 additions & 1 deletion hive/lib/src/hive.dart
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ abstract class HiveInterface implements TypeRegistry {
bool crashRecovery = true,
String? path,
@Deprecated('Use [backend] with a [StorageBackendMemory] instead')
Uint8List? bytes,
Uint8List? bytes,
StorageBackend? backend,
String? collection,
@Deprecated('Use encryptionCipher instead') List<int>? encryptionKey,
@@ -86,6 +86,8 @@ abstract class HiveInterface implements TypeRegistry {
/// Checks if a box exists
Future<bool> boxExists(String name, {String? path});

Iterable<String> listBoxes();

/// Clears all registered adapters.
///
/// To register an adapter use [registerAdapter].
14 changes: 11 additions & 3 deletions hive/lib/src/hive_impl.dart
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ class HiveImpl extends TypeRegistryImpl implements HiveInterface {

bool useLocks = true;

bool wasInitialized=false;
bool wasInitialized = false;

/// Not part of public API
HiveImpl() {
@@ -58,7 +58,7 @@ class HiveImpl extends TypeRegistryImpl implements HiveInterface {
homePath = path;
_managerOverride = BackendManager.select(backendPreference);
this.useLocks = useLocks;
wasInitialized=true;
wasInitialized = true;
}

Future<BoxBase<E>> _openBox<E>(
@@ -138,7 +138,7 @@ class HiveImpl extends TypeRegistryImpl implements HiveInterface {
bool crashRecovery = true,
String? path,
@Deprecated('Use [backend] with a [StorageBackendMemory] instead')
Uint8List? bytes,
Uint8List? bytes,
StorageBackend? backend,
String? collection,
@Deprecated('Use encryptionCipher instead') List<int>? encryptionKey,
@@ -268,6 +268,14 @@ class HiveImpl extends TypeRegistryImpl implements HiveInterface {
var lowerCaseName = name.toLowerCase();
return await manager.boxExists(lowerCaseName, path ?? homePath, collection);
}

@override
Iterable<String> listBoxes() {
var boxesNames = _boxes.values.toList().map((box) {
return box.name;
});
return boxesNames;
}
}

/// tiny helper for map key management...