sqlite

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 20 Imported by: 3

Documentation

Index

Constants

View Source
const (
	Persistence cdriver.PersistenceType = "sqlite"
)

Variables

View Source
var IsolationLevels = isolationLevelMapper{
	driver.LevelDefault:      sql.LevelDefault,
	driver.LevelSerializable: sql.LevelSerializable,
}

Functions

func NewKeyValueStoreNotifier

func NewKeyValueStoreNotifier(dbs *drivercommon.RWDB, table string) (*notifier.UnversionedPersistenceNotifier, error)

func NewNamedDriver

func NewNamedDriver(config driver.Config, dbProvider DbProvider) driver.NamedDriver

func NewPersistenceWithOpts

func NewPersistenceWithOpts[V drivercommon.DBObject](cfg *ConfigProvider, dbProvider DbProvider, name driver.PersistenceName, constructor sqlcommon.PersistenceConstructor[V], params ...string) (V, error)

NewPersistenceWithOpts constructs a V backed by the sqlite persistence configured under name and params: it resolves the connection options and table names, opens the database, and invokes constructor to build the store, creating its schema unless configured to skip.

func NewRetryWriteDB

func NewRetryWriteDB(db *sql.DB) *retryWriteDB

NewRetryWriteDB wraps the write pool db so busy Exec statements are retried.

func PrimaryKeyColumns added in v0.27.0

func PrimaryKeyColumns(q rowQuerier, table string) (string, error)

PrimaryKeyColumns returns table's primary-key columns in index order, joined by commas. The table name is bound, so a connection that rejects double-quoted string literals still works.

func ReorderPrimaryKey added in v0.27.0

func ReorderPrimaryKey(readDB *sql.DB, writeDB common.WriteDB, table, columnDefs, copyColumns string) error

ReorderPrimaryKey changes table's primary key from (pkey, ns) to (ns, pkey) by rebuilding the table in one transaction. SQLite cannot replace a primary key in place. columnDefs declares the staging table's columns, without a primary key, such as "ns TEXT NOT NULL, pkey BYTEA NOT NULL"; the staging table gets PRIMARY KEY (ns, pkey). copyColumns is the column list copied, in the same order on both tables, such as "ns, pkey, val".

The order is read once before the transaction, so a table that already has (ns, pkey) is left alone, and again after a write lock, so replicas sharing the file rebuild it once. Any other column order is an error and the table is left unchanged.

The rebuild holds the write lock, so other writers wait for it. A replica that waits longer than busy_timeout fails with SQLITE_BUSY and finds the table already reordered on its next start. This function does not retry that error.

Types

type AuditInfoStore

type AuditInfoStore struct {
	*sqlcommon.AuditInfoStore
}

func NewAuditInfoStore

func NewAuditInfoStore(dbs *drivercommon.RWDB, tables sqlcommon.TableNames) (*AuditInfoStore, error)

type BindingStore

type BindingStore struct {
	*sqlcommon.BindingStore
	// contains filtered or unexported fields
}

func NewBindingStore

func NewBindingStore(dbs *drivercommon.RWDB, tables sqlcommon.TableNames) (*BindingStore, error)

type Config

type Config struct {
	TablePrefix     string
	DataSource      string
	SkipPragmas     bool
	MaxOpenConns    int
	MaxIdleConns    *int
	MaxIdleTime     *time.Duration
	SkipCreateTable bool
	TableNameParams []string
	Tracing         *sqlcommon.TracingConfig
}

type ConfigProvider

type ConfigProvider struct {
	// contains filtered or unexported fields
}

func NewConfigProvider

func NewConfigProvider(config config) *ConfigProvider

func (*ConfigProvider) GetOpts

func (r *ConfigProvider) GetOpts(name driver.PersistenceName, params ...string) (*Config, error)

type DbProvider

type DbProvider interface {
	Get(Opts) (*common.RWDB, error)
}

func NewDbProvider

func NewDbProvider() DbProvider

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

func NewDriver

func NewDriver(config driver.Config) *Driver

func NewDriverWithDbProvider

func NewDriverWithDbProvider(config driver.Config, dbProvider DbProvider) *Driver

func (*Driver) NewAuditInfo

func (d *Driver) NewAuditInfo(name driver.PersistenceName, params ...string) (driver.AuditInfoStore, error)

func (*Driver) NewBinding

func (d *Driver) NewBinding(name driver.PersistenceName, params ...string) (driver.BindingStore, error)

func (*Driver) NewKVS

func (d *Driver) NewKVS(name driver.PersistenceName, params ...string) (driver.KeyValueStore, error)

func (*Driver) NewSignerInfo

func (d *Driver) NewSignerInfo(name driver.PersistenceName, params ...string) (driver.SignerInfoStore, error)

type ErrorMapper

type ErrorMapper struct{}

ErrorMapper maps modernc SQLite errors onto the sentinels of the storage driver package, so that callers match them with errors.Is independently of the backend.

func (*ErrorMapper) WrapError

func (*ErrorMapper) WrapError(err error) error

WrapError returns err wrapped around the sentinel its result code maps to, or err unchanged when it is not a SQLite error or its code is not mapped.

type KeyValueStore

type KeyValueStore struct {
	*sqlcommon.KeyValueStore
	// contains filtered or unexported fields
}

func NewKeyValueStore

func NewKeyValueStore(dbs *drivercommon.RWDB, tables sqlcommon.TableNames) (*KeyValueStore, error)

func (*KeyValueStore) CreateSchema added in v0.27.0

func (db *KeyValueStore) CreateSchema() error

CreateSchema creates the key-value table and reorders a primary key of (pkey, ns) to (ns, pkey). The staging table uses the KVS columns: pkey is BYTEA and val is BYTEA NOT NULL.

type Opts

type Opts struct {
	DataSource      string
	SkipPragmas     bool
	MaxOpenConns    int
	MaxIdleConns    int
	MaxIdleTime     time.Duration
	TablePrefix     string
	TableNameParams []string
	Tracing         *sqlcommon.TracingConfig
}

type SignerInfoStore

type SignerInfoStore struct {
	*sqlcommon.SignerInfoStore
}

func NewSignerInfoStore

func NewSignerInfoStore(dbs *drivercommon.RWDB, tables sqlcommon.TableNames) (*SignerInfoStore, error)

Jump to

Keyboard shortcuts

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