https://github.com/benbjohnson/litestream-library-example
Example repository for embedding Litestream in a Go application.
https://github.com/benbjohnson/litestream-library-example
Last synced: 10 months ago
JSON representation
Example repository for embedding Litestream in a Go application.
- Host: GitHub
- URL: https://github.com/benbjohnson/litestream-library-example
- Owner: benbjohnson
- License: apache-2.0
- Created: 2021-04-29T21:48:17.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-03-11T16:19:27.000Z (almost 4 years ago)
- Last Synced: 2025-03-15T23:56:14.399Z (10 months ago)
- Language: Go
- Size: 40 KB
- Stars: 58
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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:
```sh
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:
```sh
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.
```sh
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.