-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d6ba76
commit 8b45cfa
Showing
1 changed file
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# hive_mirror | ||
|
||
One way sync for hive databases. | ||
|
||
This package is in development. API might change. | ||
|
||
## Usage | ||
|
||
```dart | ||
// Hive setup has to be done using the HiveMirror api. | ||
HiveMirror.init('myHivePath'); | ||
HiveMirror.registerAdapter(PersonAdapter()); | ||
final source = FileDescriptor.file( | ||
File('myFilePath'), | ||
decode: (line) { | ||
final tupple = line.split(':'); | ||
return Person() | ||
..name = tupple[0] | ||
..age = tupple[1]; | ||
}, | ||
decodeKey: (line) { | ||
final tupple = line.split(':'); | ||
return tupple[0]; | ||
}, | ||
); | ||
// Box is synced with the data source | ||
final box = await Hive.openMirrorBox<Person>('myBox', mirrorSource: source); | ||
``` | ||
|
||
## Supported backends | ||
|
||
HiveMirror currently supports files and git patches data sources. | ||
|
||
### Text file | ||
|
||
Both local and remote files are supported as mirror data sources. | ||
Each line of the file must describe a box entry which is decoded and put in the box during the mirror operation. | ||
A file is processed only if it has changed since the last mirror operation. | ||
|
||
```dart | ||
final source = FileDescriptor.file( | ||
File('myFilePath'), | ||
decode: (line) { | ||
final tupple = line.split(':'); | ||
return Person() | ||
..name = tupple[0] | ||
..age = tupple[1]; | ||
}, | ||
decodeKey: (line) { | ||
final tupple = line.split(':'); | ||
return tupple[0]; | ||
}, | ||
); | ||
``` | ||
|
||
### Git patch | ||
|
||
HiveMirror relies on git patches to support incremental sync. | ||
A git patch is formatted using the commit from the last mirror operation. | ||
Each diff line is then decoded and either put or deleted from the box. | ||
|
||
Github compare view is used as the patch provider. | ||
|
||
```dart | ||
final source = GitPatch.githubCompareView('myGithubUserName', 'myRepoName', | ||
initialBaseRevision: 'initialRevision', | ||
compareRevision: 'master', | ||
filter: (filePath) => filePath == 'myFileToSync', | ||
decode: (filePath, line) { | ||
final tupple = line.split(':'); | ||
return Person() | ||
..name = tupple[0] | ||
..age = tupple[1]; | ||
}, | ||
decodeKey: (filePath, line) { | ||
final tupple = line.split(':'); | ||
return tupple[0]; | ||
}, | ||
); | ||
``` | ||
|
||
## Limitations | ||
|
||
HiveMirror operates inside an isolate. So it will not work in flutter web. |