Documentation
¶
Overview ¶
Package sqlitezstd provides a read-only SQLite VFS for opening Zstandard "seekable" compressed SQLite database files, either from the local filesystem or over HTTP(S) using range requests.
Importing the package for its side effects registers a VFS named "zstd":
import _ "github.com/jtarchie/sqlitezstd"
db, err := sql.Open("sqlite3", "path/to/db.sqlite.zst?vfs=zstd")
The source database must first be compressed into the zstd seekable format (see the README). The VFS is strictly read-only: writes, journals, and WAL files are rejected.
For HTTP(S) sources, pass an http:// or https:// URL as the filename. The server must support HTTP range requests (responding 206 with a Content-Range header).
Use Register to register the VFS under a different name with tuned Options (frame-cache size, HTTP timeouts, retries, logger).
Index ¶
- Constants
- func Init() errordeprecated
- func Register(name string, opts ...Option) error
- type Option
- type Options
- type ZstdFile
- func (z *ZstdFile) CheckReservedLock() (bool, error)
- func (z *ZstdFile) Close() error
- func (z *ZstdFile) DeviceCharacteristics() sqlite3vfs.DeviceCharacteristic
- func (z *ZstdFile) FileSize() (int64, error)
- func (z *ZstdFile) Lock(elock sqlite3vfs.LockType) error
- func (z *ZstdFile) ReadAt(p []byte, off int64) (int, error)
- func (z *ZstdFile) SectorSize() int64
- func (z *ZstdFile) Sync(flag sqlite3vfs.SyncType) error
- func (z *ZstdFile) Truncate(size int64) error
- func (z *ZstdFile) Unlock(elock sqlite3vfs.LockType) error
- func (z *ZstdFile) WriteAt(p []byte, off int64) (int, error)
- type ZstdVFS
Constants ¶
const ( // DefaultFrameCacheSize is the number of decoded zstd frames cached per // opened file. DefaultFrameCacheSize = 64 // DefaultHTTPTimeout bounds dialing and waiting for response headers on the // HTTP(S) path so a hung server cannot block a query indefinitely. DefaultHTTPTimeout = 30 * time.Second // DefaultHTTPMaxRetries is how many times a transient HTTP failure (network // error, 5xx, 429) is retried before the read fails. Reads are idempotent // against an immutable source, so retrying is safe. DefaultHTTPMaxRetries = 3 )
Default option values. These are applied by Register and by the default "zstd" VFS registered in init().
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
type Option func(*Options)
Option mutates an Options. See WithFrameCacheSize, WithHTTPTimeout, WithHTTPRetries, and WithLogger.
func WithFrameCacheSize ¶
WithFrameCacheSize sets the number of decoded zstd frames cached per opened file. Values <= 0 are ignored (the default is kept).
func WithHTTPClient ¶
WithHTTPClient is a convenience that uses the client's Transport as the base round-tripper (see WithRoundTripper). A nil client is ignored.
func WithHTTPRetries ¶
WithHTTPRetries sets the number of retries for transient HTTP failures. Negative values are ignored; 0 disables retries.
func WithHTTPTimeout ¶
WithHTTPTimeout sets the dial and response-header timeout for the HTTP(S) path. Values <= 0 are ignored.
func WithLogger ¶
WithLogger sets the logger used to report otherwise-opaque open/read failures (the sqlite3vfs interface can only return fixed sentinel errors, so the real cause is logged). A nil logger is ignored.
func WithRoundTripper ¶
func WithRoundTripper(rt http.RoundTripper) Option
WithRoundTripper sets the base http.RoundTripper used for the HTTP(S) path. The library still wraps it with retry and Range-response validation, so a caller can supply, for example, a request-signing transport for authenticated buckets without losing those protections. A nil transport is ignored.
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options configures a registered VFS. Construct it with Option values passed to Register; the zero value is not valid (use Register, which fills in defaults).
type ZstdFile ¶
type ZstdFile struct {
// contains filtered or unexported fields
}
ZstdFile is a read-only sqlite3vfs.File backed by a zstd-seekable reader.
func (*ZstdFile) CheckReservedLock ¶
func (*ZstdFile) DeviceCharacteristics ¶
func (z *ZstdFile) DeviceCharacteristics() sqlite3vfs.DeviceCharacteristic
func (*ZstdFile) SectorSize ¶
type ZstdVFS ¶
type ZstdVFS struct {
// contains filtered or unexported fields
}
ZstdVFS is a read-only sqlite3vfs.VFS for zstd-seekable compressed databases.
func (*ZstdVFS) Access ¶
func (z *ZstdVFS) Access(name string, flags sqlite3vfs.AccessFlag) (bool, error)
func (*ZstdVFS) FullPathname ¶
func (*ZstdVFS) Open ¶
func (z *ZstdVFS) Open(name string, flags sqlite3vfs.OpenFlag) (sqlite3vfs.File, sqlite3vfs.OpenFlag, error)