GithubHelp home page GithubHelp logo

hive_mirror's Introduction

hive_mirror

One way sync for hive databases.

This package is in development. API might change.

Usage

// 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.

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.

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.

hive_mirror's People

Contributors

guillaumeducret avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.