Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/joutvhu/hive_wait
- Owner: joutvhu
- License: mit
- Created: 2022-05-10T04:50:38.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-07-28T07:04:00.000Z (over 1 year ago)
- Last Synced: 2024-11-08T21:38:20.810Z (about 2 months ago)
- Topics: box, dart, database, hive, lazy, repository
- Language: Dart
- Homepage: https://pub.dev/packages/hive_wait
- Size: 19.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
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);
}
```