Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/joutvhu/hive_wait

Hive Wait provide a Hive repository to calling methods in the box as async. Wait until the Hive is ready to use before calling the box's methods.
https://github.com/joutvhu/hive_wait

box dart database hive lazy repository

Last synced: 1 day ago
JSON representation

Hive Wait provide a Hive repository to calling methods in the box as async. Wait until the Hive is ready to use before calling the box's methods.

Awesome Lists containing this project

README

        

# Hive Wait

Hive Wait provide a Hive repository to calling methods in the box as async.

Wait until the Hive is ready to use before calling the box's methods.

## Usage

- Wait init Hive
```dart
class CoreRepository extends HiveRepository {
CoreRepository(
String name, {
bool? lazy,
HiveCipher? encryptionCipher,
KeyComparator? keyComparator,
CompactionStrategy? compactionStrategy,
bool? crashRecovery,
String? boxPath,
Uint8List? bytes,
}) : super(
name,
lazy: lazy,
encryptionCipher: encryptionCipher,
keyComparator: keyComparator,
compactionStrategy: compactionStrategy,
crashRecovery: crashRecovery,
boxPath: boxPath,
bytes: bytes,
);

@override
Future> init([HiveInterface? hive]) async {
await Hive.initFlutter();
// TODO: Register adapter
return await super.init(Hive);
}
}
```

- Using with get_it
```dart
class CoreRepository extends HiveRepository {
CoreRepository(
String name, {
bool? lazy,
}) : super(name, lazy: lazy);

@override
Future> init([HiveInterface? hive]) async {
await getIt.allReady();
hive = await getIt.getAsync();
return await super.init(hive);
}
}

// TODO: register a singleton with get_it
class PropertyRepository extends CoreRepository {
PropertyRepository() : super('property');
}
```

- Get data
```dart
getUser() async {
var userRepository = CoreRepository('user');
return await userRepository.get(0);
}
```