Help us shape the future of Go! Take the 2026 Go Developer Survey

litestream

package module
v0.30.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2025 License: MIT Imports: 16 Imported by: 1

README

Litestream lightweight read-replicas

This package implements the EXPERIMENTAL "litestream" SQLite VFS that offers Litestream lightweight read-replicas.

See the example for how to use.

Our PRAGMA litestream_time accepts:

Documentation

Overview

Package litestream implements a Litestream lightweight read-replica VFS.

Index

Examples

Constants

View Source
const (
	// The default poll interval.
	DefaultPollInterval = 1 * time.Second

	// The default cache size: 10 MiB.
	DefaultCacheSize = 10 * 1024 * 1024
)

Variables

This section is empty.

Functions

func NewReplica

func NewReplica(name string, client ReplicaClient, options ReplicaOptions)

NewReplica creates a read-replica from a Litestream client.

Example
package main

import (
	"log"
	"time"

	"github.com/benbjohnson/litestream/s3"

	"github.com/ncruces/go-sqlite3/driver"
	_ "github.com/ncruces/go-sqlite3/embed"
	"github.com/ncruces/go-sqlite3/litestream"
)

func main() {
	client := s3.NewReplicaClient()
	client.Bucket = "test-bucket"
	client.Path = "fruits.db"

	litestream.NewReplica("fruits.db", client, litestream.ReplicaOptions{
		PollInterval: 5 * time.Second,
	})

	db, err := driver.Open("file:fruits.db?vfs=litestream")
	if err != nil {
		log.Fatalln(err)
	}
	defer db.Close()

	for {
		time.Sleep(time.Second)
		rows, err := db.Query("SELECT * FROM fruits")
		if err != nil {
			log.Fatalln(err)
		}

		for rows.Next() {
			var name, color string
			err := rows.Scan(&name, &color)
			if err != nil {
				log.Fatalln(err)
			}
			log.Println(name, color)
		}

		log.Println("===")
		rows.Close()
	}
}

func RemoveReplica

func RemoveReplica(name string)

RemoveReplica removes a replica by name.

Types

type ReplicaClient added in v0.30.4

type ReplicaClient = litestream.ReplicaClient

type ReplicaOptions

type ReplicaOptions struct {
	// Where to log error messages. May be nil.
	Logger *slog.Logger

	// Replica poll interval.
	// Should be less than the compaction interval
	// used by the replica at MinLevel+1.
	PollInterval time.Duration

	// CacheSize is the maximum size of the page cache in bytes.
	// Zero means DefaultCacheSize, negative disables caching.
	CacheSize int
}

ReplicaOptions represents options for NewReplica.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL