sqlite3ha

package module
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 8 Imported by: 3 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-sqlite3-ha

Go database/sql driver based on github.com/mattn/go-sqlite3, providing high availability for SQLite databases.

Features

  • Built on the robust foundation of go-sqlite3.
  • High availability support for SQLite databases.
  • Replication: Synchronize data across nodes using NATS.
  • Customize the replication strategy
  • Leaderless clusters: Read/Write from/to any node. Last-writer wins by default, but you can customize conflict resolutions by implementing ChangeSetInterceptor.
  • Embedded or External NATS: Choose between an embedded NATS server or an external one for replication.
  • Easy to integrate with existing Go projects.

Installation

go get github.com/litesql/go-sqlite3-ha

Usage

package main

import (
    "database/sql"
    _ "github.com/litesql/go-sqlite3-ha"
)

func main() {
    db, err := sql.Open("sqlite3-ha", "file:example.db?_journal=WAL&_timeout=5000&replicationURL=nats://broker:4222&name=node0")
    if err != nil {
        panic(err)
    }
    defer db.Close()

    // Use db to interact with your database
}
Using Connector
package main

import (
    "database/sql"
    sqlite3ha "github.com/litesql/go-sqlite3-ha"
)

func main() {
    c, err := sqlite3.NewConnector("file:example.db?_journal=WAL&_timeout=5000",
		ha.WithName("node1"),
		ha.WithEmbeddedNatsConfig(&ha.EmbeddedNatsConfig{
			Port: 4222,
		}))
	if err != nil {
		panic(err)
	}
	defer c.Close()

	db := sql.OpenDB(c)
	defer db.Close()

    // Use db to interact with your database
}

Configuration

See options available

Projects using go-ha

  • HA: Highly available leaderless SQLite cluster with HTTP and PostgreSQL Wire Protocol
  • PocketBase HA: Highly available leaderless PocketBase cluster

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTimedOut = ha.ErrTimedOut

Functions

func Backup

func Backup(ctx context.Context, db *sql.DB, w io.Writer) error

func NewConnector

func NewConnector(name string, opts ...ha.Option) (*ha.Connector, error)

Types

type Conn

type Conn = ha.Conn

type Driver

type Driver struct {
	Extensions  []string
	ConnectHook func(*sqlite3.SQLiteConn) error
	Options     []ha.Option
}

func (*Driver) Open

func (d *Driver) Open(name string) (driver.Conn, error)

func (*Driver) OpenConnector

func (d *Driver) OpenConnector(name string) (driver.Connector, error)

type ProxiedQuerierExecer added in v0.11.8

type ProxiedQuerierExecer = ha.ProxiedQuerierExecer

Directories

Path Synopsis
_examples
2pc/peer1 command
2pc/peer2 command
node1 command
node2 command
shards command

Jump to

Keyboard shortcuts

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