Documentation
¶
Overview ¶
Package litestream implements a Litestream lightweight read-replica VFS.
Index ¶
Examples ¶
Constants ¶
View Source
const DefaultPollInterval = 1 * time.Second
The default poll interval.
Variables ¶
This section is empty.
Functions ¶
func NewReplica ¶
func NewReplica(name string, client litestream.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/litestream"
_ "github.com/ncruces/go-sqlite3/embed"
)
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()
}
}
Types ¶
type ReplicaOptions ¶
type ReplicaOptions struct {
// Where to log error messages. May be nil.
Logger *slog.Logger
// Minimum compaction level to track.
MinLevel int
// Replica poll interval. Must be less than the compaction interval
// used by the replica at MinLevel+1.
PollInterval time.Duration
}
ReplicaOptions represents options for NewReplica.
Click to show internal directories.
Click to hide internal directories.