sqlite

package
v0.0.0-...-e6a591c Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PragmaSynchronous    = "synchronous"
	PragmaJournalMode    = "journal_mode"
	PragmaWalCheckpoint  = "wal_checkpoint"
	PragmaCacheSize      = "cache_size"
	PragmaApplicationID  = "application_id"
	PragmaAutoVacuum     = "auto_vacuum"
	PragmaAutomaticIndex = "automatic_index"
	PragmaDataVersion    = "data_version"
	PragmaDatabaseList   = "database_list"
)

Variables

This section is empty.

Functions

func File

func File(location string, opts ...Option) (*sql.DB, error)

func GetJournalMode

func GetJournalMode(database db.DB) (string, error)

func GetPragma

func GetPragma[T any](database db.DB, name string) (T, error)

func GetPragmaCacheSize

func GetPragmaCacheSize(database db.DB) (int64, error)

func GetWalCheckpoint

func GetWalCheckpoint(database db.DB) (int, int, int, error)

func InMemory

func InMemory(opts ...Option) (*sql.DB, error)

func ListTablesNames

func ListTablesNames(db db.DB) ([]string, error)

func Open

func Open(location string, config *Config) (*sql.DB, error)

func OpenURI

func OpenURI(uri *url.URL, opts ...Option) (*sql.DB, error)

func ReadOnly

func ReadOnly(c *Config)

Types

type CacheMode

type CacheMode uint8

CacheMode is used to configure the 'cache' URI parameter.

See https://www.sqlite.org/uri.html

const (
	// CacheModeNone is the default value and will not affect the connect URI.
	CacheModeNone CacheMode = iota
	// CacheModeShared will be used to add the URI query parameter '?cache=shared'.
	CacheModeShared
	// CacheModeShared will be used to add the URI query parameter '?cache=private'.
	CacheModePrivate
)

type Config

type Config struct {
	ReadOnly    bool
	Cache       CacheMode
	JournalMode string
	// WalCheckpoint is only used when JournalMode is "WAL"
	WalCheckpoint *int
	Pragmas       map[string]any
	Debug         bool
}

type DatabaseList

type DatabaseList struct {
	Index    int
	Name     string
	Location string
}

func GetPragmaDatabaseList

func GetPragmaDatabaseList(database db.DB) ([]DatabaseList, error)

type Option

type Option func(c *Config)

func Cache

func Cache(mode CacheMode) Option

func JournalMode

func JournalMode(mode string) Option

JournalMode sets the database's journal_mode pragma.

func WalCheckpoint

func WalCheckpoint(n int) Option

WalCheckpoint sets the database's wal_checkpoint pragma.

func WithCacheMode

func WithCacheMode(mode CacheMode) Option

func WithPragma

func WithPragma(name string, value any) Option

Pragma will add a database pragma.

Calling Pragma("journal_mode", "WAL") will end up executing PRAGMA journal_mode = WAL;

type Synchronous

type Synchronous uint8

See https://www.sqlite.org/pragma.html

const (
	SynchronousOff Synchronous = iota
	SynchronousNormal
	SynchronousFull
	SynchronousExtra
)

func GetPragmaSynchronous

func GetPragmaSynchronous(database db.DB) (Synchronous, error)

Jump to

Keyboard shortcuts

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