Documentation
¶
Overview ¶
Package replicadb provides a SQLite database wrapper with Litestream-based replication support. It separates read-only and write connections and supports primary and replica database configurations.
Index ¶
- type ABSConfiguration
- type DB
- type GCSConfiguration
- type Option
- func WithABSReplication(config ABSConfiguration) Option
- func WithBusyTimeout(timeout time.Duration) Option
- func WithCacheSize(size int) Option
- func WithFileReplication(path string) Option
- func WithGCSReplication(config GCSConfiguration) Option
- func WithMaxConnections(conn int) Option
- func WithRestoreParallelism(parallelism int) Option
- func WithS3Replication(config S3Configuration) Option
- func WithSyncInterval(interval time.Duration) Option
- type S3Configuration
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ABSConfiguration ¶
type ABSConfiguration struct {
// AccountName is the Azure storage account name.
AccountName string
// AccountKey is the access key for the Azure storage account.
AccountKey string
// Endpoint is an optional custom Azure Blob Storage endpoint.
// This is commonly used for emulators or private cloud deployments.
Endpoint string
// Bucket is the name of the Azure Blob Storage container.
Bucket string
// Path is the prefix within the container under which
// database replicas will be stored.
Path string
}
ABSConfiguration defines the configuration required to use Azure Blob Storage (ABS) as a Litestream replication backend.
type DB ¶
type DB struct {
// DB is the read-only database handle used for concurrent reads.
*sql.DB
// contains filtered or unexported fields
}
DB represents a replicated SQLite database.
It embeds a read-only *sql.DB for concurrent queries and, when initialized as a primary, a single-threaded write database for mutations backed by an embedded litestream instance. When configured as a replica, it only gets the read-only database and periodically syncs from the remote source.
func Memory ¶
Memory opens a memory-based primary database.
This is predominantly used for testing and does no replication whatsoever. Note that it also doesn't open up a connection to a real read-only DB, as it shares the connection between read and write.
func Open ¶
Open opens a primary database at the given path.
It initializes Litestream replication if a replica client is configured, attempts a restore if necessary, and returns a DB with separate read-only and write connections.
func OpenReplica ¶
OpenReplica opens a read-only replica database at the given path.
The replica periodically synchronizes from the primary using the configured replica client. Write access is not supported.
type GCSConfiguration ¶
type GCSConfiguration struct {
// Bucket is the name of the Google Cloud Storage bucket
// used to store database replicas.
Bucket string
// Path is an optional prefix within the bucket under which
// database replicas will be stored.
Path string
}
GCSConfiguration defines the configuration required to use Google Cloud Storage (GCS) as a Litestream replication backend.
type Option ¶
type Option func(db *DB)
Option configures a DB during construction.
func WithABSReplication ¶
func WithABSReplication(config ABSConfiguration) Option
WithABSReplication configures the database to use Azure Blob Storage as its Litestream replication backend.
When applied, this option initializes an ABS replica client and attaches it to the DB. The client is used when opening the database as either a primary or replica via Open or OpenReplica.
func WithBusyTimeout ¶
WithBusyTimeout sets the SQLite busy timeout duration.
func WithCacheSize ¶
WithCacheSize sets the SQLite page cache size, in bytes.
func WithFileReplication ¶
WithFileReplication configures the database to use the local filesystem as its Litestream replication backend.
The provided path specifies the directory where replica data will be stored. This option is useful for local development, testing, or single-node deployments where remote object storage is not required.
func WithGCSReplication ¶
func WithGCSReplication(config GCSConfiguration) Option
WithGCSReplication configures the database to use Google Cloud Storage as its Litestream replication backend.
When applied, this option initializes a GCS replica client and attaches it to the DB. The client is used when opening the database as either a primary or replica via Open or OpenReplica.
func WithMaxConnections ¶
WithMaxConnections sets the maximum number of connections on the read-only DB.
func WithRestoreParallelism ¶
WithRestoreParallelism sets the number of parallel workers used when restoring a primary database from a replica.
func WithS3Replication ¶
func WithS3Replication(config S3Configuration) Option
WithS3Replication configures the database to use Amazon S3–compatible object storage as its Litestream replication backend.
When applied, this option initializes an S3 replica client and attaches it to the DB. The client is used when opening the database as either a primary or replica via Open or OpenReplica.
func WithSyncInterval ¶
WithSyncInterval sets the polling interval used by replicas to synchronize from the primary.
type S3Configuration ¶
type S3Configuration struct {
// AccessKeyID is the AWS access key ID used for authentication.
AccessKeyID string
// SecretAccessKey is the AWS secret access key used for authentication.
SecretAccessKey string
// Region is the AWS region where the S3 bucket resides.
Region string
// Bucket is the name of the S3 bucket used to store database replicas.
Bucket string
// Path is the prefix within the bucket under which
// database replicas will be stored.
Path string
// Endpoint is an optional custom S3 endpoint.
// This is commonly used for S3-compatible storage providers.
Endpoint string
// ForcePathStyle forces path-style addressing instead of virtual-hosted style.
ForcePathStyle bool
// SkipVerify disables TLS certificate verification.
// This should only be used in development or testing environments.
SkipVerify bool
// SignPayload enables request payload signing.
SignPayload bool
// RequireContentMD5 enforces Content-MD5 validation on uploads.
RequireContentMD5 bool
// PartSize is the size of each part for multipart uploads.
// If zero, the Litestream default (5MB) is used.
PartSize int64 // Part size for multipart uploads (default: 5MB)
// Concurrency is the number of concurrent parts uploaded during
// multipart uploads. If zero, the Litestream default (5) is used.
Concurrency int // Number of concurrent parts to upload (default: 5)
}
S3Configuration defines the configuration required to use Amazon S3–compatible object storage as a Litestream replication backend.
This configuration supports AWS S3 as well as S3-compatible providers such as MinIO, DigitalOcean Spaces, and others.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package durabletask provides a replicadb-backed implementation of the Durable Task Framework backend interfaces.
|
Package durabletask provides a replicadb-backed implementation of the Durable Task Framework backend interfaces. |