sqlite

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 21 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, preparing its schema with migrate.CreateSchema. With skipCreateTable it runs no schema step and fails with migrate.ErrPending if the store has steps pending.

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.

func ReorderPrimaryKeyTx added in v0.28.0

func ReorderPrimaryKeyTx(ctx context.Context, q migrate.Execer, table, columnDefs, copyColumns string) error

ReorderPrimaryKeyTx is ReorderPrimaryKey inside the caller's transaction q, which must already hold the write lock, such as a BEGIN IMMEDIATE transaction: it reads the key order and rebuilds a table keyed (pkey, ns). Any order other than (ns, pkey) or (pkey, ns) is an 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
	// QueryTimeout bounds each statement, and each write transaction as a whole;
	// zero adds no deadline.
	QueryTimeout time.Duration
}

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)

func (*ConfigProvider) MigrateOptions added in v0.28.0

func (r *ConfigProvider) MigrateOptions(skipCreateTable bool) ([]migrate.Option, error)

MigrateOptions returns the migrate options of a persistence with the given skipCreateTable; see sqlcommon.MigrateOptions.

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, with its context, 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).

func (*KeyValueStore) Steps added in v0.28.0

func (db *KeyValueStore) Steps() []migrate.Step

Steps returns the store's schema steps. Step 1 creates the table if it does not exist and reorders a primary key of (pkey, ns) to (ns, pkey).

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