Git Product home page Git Product logo

litestream-library-example's Introduction

Litestream as Library

This repository is an example of embedding Litestream as a library in a Go application. The Litestream API is not stable so you may need to update your code in the future when you upgrade.

Install

To install, run:

go install .

You should now have a litestream-library-example in $GOPATH/bin.

Usage

This example application uses AWS S3 and only provides a -bucket configuration flag. It will pull AWS credentials from environment variables so you will need to set those:

export AWS_ACCESS_KEY_ID=xxxxxxxxxxxxxxxxxxxx
export AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

You'll need to setup an S3 bucket and use that name when running the app.

litestream-library-example -dsn /path/to/db -bucket YOURBUCKETNAME

On your first run, it will see that there is no snapshot available so the application will create a new database. If you restart the application then it will see the local database and use that.

If you remove the database:

rm /path/to/db* /path/to/.db-litestream

Then when you restart the application, it will fetch the latest snapshot and replay all WAL files up to the latest position.

Synchronous replication

This repository provides an example of confirming that the replica syncs to S3 before returning to the caller. Replicating to S3 can be slow so you may end up waiting several hundred milliseconds before the sync returns.

litestream-library-example's People

Contributors

benbjohnson avatar leslie-wang 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.