Documentation
¶
Overview ¶
Package db exposes a lightweight abstraction over the SQLite code. It performs some basic mapping of lower-level types to rqlite types.
Index ¶
- Constants
- Variables
- func CheckpointRemove(path string) error
- func EnsureDeleteMode(path string) error
- func EnsureWALMode(path string) error
- func IsBreakingPragma(stmt string) bool
- func IsDELETEModeEnabled(b []byte) bool
- func IsDELETEModeEnabledSQLiteFile(path string) (bool, error)
- func IsValidSQLiteData(b []byte) bool
- func IsValidSQLiteFile(path string) bool
- func IsValidSQLiteFileCompressed(path string) bool
- func IsValidSQLiteWALData(b []byte) bool
- func IsValidSQLiteWALFile(path string) bool
- func IsWALModeEnabled(b []byte) bool
- func IsWALModeEnabledSQLiteFile(path string) (bool, error)
- func MakeDSN(path string, readOnly, fkEnabled, walEnabled bool) string
- func ParseHex(s string) ([]byte, error)
- func RemoveFiles(path string) error
- func RemoveWALFiles(path string) error
- func ReplayWAL(path string, wals []string, deleteMode bool) error
- func ResetStats()
- func ValidateExtension(path string) error
- func WALPath(dbPath string) string
- type CheckpointMode
- type CnkOnCloseMode
- type CommitHookCallback
- type DB
- func (db *DB) Backup(path string, vacuum bool) error
- func (db *DB) BusyTimeout() (rwMs, roMs int, err error)
- func (db *DB) Checkpoint(mode CheckpointMode) error
- func (db *DB) CheckpointWithTimeout(mode CheckpointMode, dur time.Duration) (err error)
- func (db *DB) Close() error
- func (db *DB) CompileOptions() ([]string, error)
- func (db *DB) ConnectionPoolStats(sqlDB *sql.DB) *PoolStats
- func (db *DB) Copy(dstDB *DB) error
- func (db *DB) DBLastModified() (time.Time, error)
- func (db *DB) DBSum() (string, error)
- func (db *DB) DisableCheckpointing() error
- func (db *DB) Dump(w io.Writer) error
- func (db *DB) EnableCheckpointing() error
- func (db *DB) Execute(req *command.Request, xTime bool) ([]*command.ExecuteQueryResponse, error)
- func (db *DB) ExecuteStringStmt(query string) ([]*command.ExecuteQueryResponse, error)
- func (db *DB) ExecuteStringStmtWithTimeout(query string, timeout time.Duration) ([]*command.ExecuteQueryResponse, error)
- func (db *DB) ExtensionNames() []string
- func (db *DB) FKEnabled() bool
- func (db *DB) FileSize() (int64, error)
- func (db *DB) GetCheckpointing() (int, error)
- func (db *DB) GetSynchronousMode() (SynchronousMode, error)
- func (db *DB) IntegrityCheck(full bool) ([]*command.QueryRows, error)
- func (db *DB) LastModified() (time.Time, error)
- func (db *DB) Optimize() error
- func (db *DB) OptimizeWithMask(mask int) error
- func (db *DB) Path() string
- func (db *DB) Query(req *command.Request, xTime bool) ([]*command.QueryRows, error)
- func (db *DB) QueryStringStmt(query string) ([]*command.QueryRows, error)
- func (db *DB) QueryStringStmtWithTimeout(query string, tx bool, timeout time.Duration) ([]*command.QueryRows, error)
- func (db *DB) RegisterCommitHook(hook CommitHookCallback) error
- func (db *DB) RegisterPreUpdateHook(hook PreUpdateHookCallback, rowIDsOnly bool) error
- func (db *DB) RegisterUpdateHook(hook UpdateHookCallback) error
- func (db *DB) Request(req *command.Request, xTime bool) ([]*command.ExecuteQueryResponse, error)
- func (db *DB) RequestStringStmts(stmts []string) ([]*command.ExecuteQueryResponse, error)
- func (db *DB) RequestStringStmtsWithTimeout(stmts []string, timeout time.Duration) ([]*command.ExecuteQueryResponse, error)
- func (db *DB) Serialize() ([]byte, error)
- func (db *DB) SetBusyTimeout(rwMs, roMs int) (err error)
- func (db *DB) SetSynchronousMode(mode SynchronousMode) error
- func (db *DB) Size() (int64, error)
- func (db *DB) Stats() (map[string]interface{}, error)
- func (db *DB) StmtReadOnly(sql string) (bool, error)
- func (db *DB) StmtReadOnlyWithConn(sql string, conn *sql.Conn) (bool, error)
- func (db *DB) Vacuum() error
- func (db *DB) VacuumInto(path string) error
- func (db *DB) WALEnabled() bool
- func (db *DB) WALLastModified() (time.Time, error)
- func (db *DB) WALPath() string
- func (db *DB) WALSize() (int64, error)
- func (db *DB) WALSum() (string, error)
- type Driver
- type PoolStats
- type PreUpdateHookCallback
- type SwappableDB
- func (s *SwappableDB) Backup(path string, vacuum bool) error
- func (s *SwappableDB) Checkpoint(mode CheckpointMode) error
- func (s *SwappableDB) Close() error
- func (s *SwappableDB) DBLastModified() (time.Time, error)
- func (s *SwappableDB) Dump(w io.Writer) error
- func (s *SwappableDB) Execute(ex *command.Request, xTime bool) ([]*command.ExecuteQueryResponse, error)
- func (s *SwappableDB) FKEnabled() bool
- func (s *SwappableDB) FileSize() (int64, error)
- func (s *SwappableDB) Optimize() error
- func (s *SwappableDB) Path() string
- func (s *SwappableDB) Query(q *command.Request, xTime bool) ([]*command.QueryRows, error)
- func (s *SwappableDB) QueryStringStmt(query string) ([]*command.QueryRows, error)
- func (s *SwappableDB) Request(req *command.Request, xTime bool) ([]*command.ExecuteQueryResponse, error)
- func (s *SwappableDB) Serialize() ([]byte, error)
- func (s *SwappableDB) SetSynchronousMode(mode SynchronousMode) error
- func (s *SwappableDB) Stats() (map[string]interface{}, error)
- func (s *SwappableDB) StmtReadOnly(sql string) (bool, error)
- func (s *SwappableDB) Swap(path string, fkConstraints, walEnabled bool) error
- func (s *SwappableDB) Vacuum() error
- func (s *SwappableDB) VacuumInto(path string) error
- func (s *SwappableDB) WALEnabled() bool
- func (s *SwappableDB) WALSize() (int64, error)
- type SynchronousMode
- type UpdateHookCallback
Constants ¶
const ( SQLiteHeaderSize = 32 OptimizeDefault = 0xFFFE OptimizeAll = 0x10002 )
const ( // ModeReadOnly is the mode to open a database in read-only mode. ModeReadOnly = true // ModeReadWrite is the mode to open a database in read-write mode. ModeReadWrite = false )
Variables ¶
var ( // ErrWALReplayDirectoryMismatch is returned when the WAL file(s) are not in the same // directory as the database file. ErrWALReplayDirectoryMismatch = errors.New("WAL file(s) not in same directory as database file") // ErrQueryTimeout is returned when a query times out. ErrQueryTimeout = errors.New("query timeout") // ErrExecuteTimeout is returned when an execute times out. ErrExecuteTimeout = errors.New("execute timeout") )
var BreakingPragmas = map[string]*regexp.Regexp{ "PRAGMA journal_mode": regexp.MustCompile(`(?i)^\s*PRAGMA\s+(\w+\.)?journal_mode\s*=\s*`), "PRAGMA wal_autocheckpoint": regexp.MustCompile(`(?i)^\s*PRAGMA\s+wal_autocheckpoint\s*=\s*`), "PRAGMA wal_checkpoint": regexp.MustCompile(`(?i)^\s*PRAGMA\s+(\w+\.)?wal_checkpoint`), "PRAGMA synchronous": regexp.MustCompile(`(?i)^\s*PRAGMA\s+(\w+\.)?synchronous\s*=\s*`), }
BreakingPragmas are PRAGMAs that, if executed, would break the database layer.
var DBVersion string
DBVersion is the SQLite version.
Functions ¶
func CheckpointRemove ¶ added in v8.30.1
CheckpointRemove checkpoints any WAL files into the database file at the given given path. Checkpointing a database in DELETE mode is an error.
func EnsureDeleteMode ¶ added in v8.16.1
EnsureDeleteMode ensures the database at the given path is in DELETE mode.
func EnsureWALMode ¶ added in v8.30.1
EnsureWALMode ensures the database at the given path is in WAL mode.
func IsBreakingPragma ¶ added in v8.26.8
IsBreakingPragma returns true if the given statement is a breaking PRAGMA.
func IsDELETEModeEnabled ¶
IsDELETEModeEnabled checks that the supplied data looks like a SQLite file with DELETE mode enabled.
func IsDELETEModeEnabledSQLiteFile ¶
IsDELETEModeEnabledSQLiteFile checks that the supplied path looks like a SQLite with DELETE mode enabled.
func IsValidSQLiteData ¶
IsValidSQLiteData checks that the supplied data looks like a SQLite data. See https://www.sqlite.org/fileformat.html.
func IsValidSQLiteFile ¶
IsValidSQLiteFile checks that the supplied path looks like a SQLite file. A nonexistent file is considered invalid.
func IsValidSQLiteFileCompressed ¶ added in v8.30.1
IsValidSQLiteFileCompressed checks that the supplied path looks like a compressed SQLite file. A nonexistent file, invalid Gzip archive, or gzip archive that does not contain a valid SQLite file is considered invalid.
func IsValidSQLiteWALData ¶
IsValidSQLiteWALData checks that the supplied data looks like a SQLite WAL file.
func IsValidSQLiteWALFile ¶
IsValidSQLiteWALFile checks that the supplied path looks like a SQLite WAL file. See https://www.sqlite.org/fileformat2.html#walformat. A nonexistent file is considered invalid.
func IsWALModeEnabled ¶
IsWALModeEnabled checks that the supplied data looks like a SQLite data with WAL mode enabled.
func IsWALModeEnabledSQLiteFile ¶
IsWALModeEnabledSQLiteFile checks that the supplied path looks like a SQLite with WAL mode enabled.
func MakeDSN ¶ added in v8.16.6
MakeDSN returns a SQLite DSN for the given path, with the given options.
func ParseHex ¶ added in v8.31.0
ParseHex parses the given string into a byte slice as per the SQLite specification:
BLOB literals are string literals containing hexadecimal data and preceded by a single "x" or "X" character. Example: X'53514C697465'
func RemoveFiles ¶
RemoveFiles removes the SQLite database file, and any associated WAL and SHM files.
func RemoveWALFiles ¶ added in v8.30.1
RemoveWALFiles removes the WAL and SHM files associated with the given path, leaving the database file untouched.
func ReplayWAL ¶
ReplayWAL replays the given WAL files into the database at the given path, in the order given by the slice. The supplied WAL files must be in the same directory as the database file and are deleted as a result of the replay operation. If deleteMode is true, the database file will be in DELETE mode after the replay operation, otherwise it will be in WAL mode. In either case no WAL-related files will be present.
func ResetStats ¶
func ResetStats()
ResetStats resets the expvar stats for this module. Mostly for test purposes.
func ValidateExtension ¶ added in v8.27.0
ValidateExtension validates the given extension path can be loaded into a SQLite database.
Types ¶
type CheckpointMode ¶ added in v8.18.2
type CheckpointMode int
CheckpointMode is the mode in which a checkpoint runs.
const ( // CheckpointRestart instructs the checkpoint to run in restart mode. CheckpointRestart CheckpointMode = iota // CheckpointTruncate instructs the checkpoint to run in truncate mode. CheckpointTruncate )
type CnkOnCloseMode ¶ added in v8.30.1
type CnkOnCloseMode int
CnkOnCloseMode represents the checkpoint on close mode.
const ( // CnkOnCloseModeEnabled enables checkpoint on close. CnkOnCloseModeEnabled CnkOnCloseMode = iota // CnkOnCloseModeDisabled disables checkpoint on close. CnkOnCloseModeDisabled )
type CommitHookCallback ¶ added in v8.36.17
type CommitHookCallback func() bool
CommitHookCallback is a callback function that is called whenever a transaction is committed to the database. If the callback returns true the transaction is committed, otherwise it is rolled back.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is the SQL database.
func OpenWithDriver ¶ added in v8.27.0
OpenWithDriver opens a file-based database, creating it if it does not exist. After this function returns, an actual SQLite file will always exist. If the database is opened in WAL mode, the WAL files will also be created if they do not exist.
func (*DB) Backup ¶
Backup writes a consistent snapshot of the database to the given file. The resultant SQLite database file will be in DELETE mode. This function can be called when changes to the database are in flight.
func (*DB) BusyTimeout ¶ added in v8.18.2
BusyTimeout returns the current busy timeout value.
func (*DB) Checkpoint ¶
func (db *DB) Checkpoint(mode CheckpointMode) error
Checkpoint checkpoints the WAL file. If the WAL file is not enabled, this function is a no-op.
func (*DB) CheckpointWithTimeout ¶
func (db *DB) CheckpointWithTimeout(mode CheckpointMode, dur time.Duration) (err error)
CheckpointWithTimeout performs a WAL checkpoint. If the checkpoint does not run to completion within the given duration, an error is returned. If the duration is 0, the busy timeout is not modified before executing the checkpoint.
func (*DB) CompileOptions ¶
CompileOptions returns the SQLite compilation options.
func (*DB) ConnectionPoolStats ¶
ConnectionPoolStats returns database pool statistics
func (*DB) Copy ¶
Copy copies the contents of the database to the given database. All other attributes of the given database remain untouched e.g. whether it's an on-disk database, except the database will be placed in DELETE mode. This function can be called when changes to the source database are in flight.
func (*DB) DBLastModified ¶ added in v8.16.8
DBLastModified returns the last modified time of the database file.
func (*DB) DisableCheckpointing ¶
DisableCheckpointing disables the automatic checkpointing that occurs when the WAL reaches a certain size. This is key for full control of snapshotting. and can be useful for testing.
func (*DB) Dump ¶
Dump writes a consistent snapshot of the database in SQL text format. This function can be called when changes to the database are in flight.
func (*DB) EnableCheckpointing ¶
EnableCheckpointing enables the automatic checkpointing that occurs when the WAL reaches a certain size.
func (*DB) ExecuteStringStmt ¶
func (db *DB) ExecuteStringStmt(query string) ([]*command.ExecuteQueryResponse, error)
ExecuteStringStmt executes a single query that modifies the database. This is primarily a convenience function.
func (*DB) ExecuteStringStmtWithTimeout ¶ added in v8.19.0
func (db *DB) ExecuteStringStmtWithTimeout(query string, timeout time.Duration) ([]*command.ExecuteQueryResponse, error)
ExecuteStringStmtWithTimeout executes a single query that modifies the database. It also sets a timeout for the query. This is primarily a convenience function.
func (*DB) ExtensionNames ¶ added in v8.27.0
ExtensionNames returns the names of the SQLite extensions loaded into the database.
func (*DB) FileSize ¶
FileSize returns the size of the SQLite file on disk. If running in on-memory mode, this function returns 0.
func (*DB) GetCheckpointing ¶
GetCheckpointing returns the current checkpointing setting.
func (*DB) GetSynchronousMode ¶
func (db *DB) GetSynchronousMode() (SynchronousMode, error)
GetSynchronousMode returns the current synchronous mode.
func (*DB) IntegrityCheck ¶ added in v8.16.8
IntegrityCheck runs a PRAGMA integrity_check on the database. If full is true, a full integrity check is performed, otherwise a quick check. It returns after hitting the first integrity failure, if any.
func (*DB) LastModified ¶ added in v8.16.1
LastModified returns the last modified time of the database file, or the WAL file, whichever is most recent.
func (*DB) Optimize ¶ added in v8.30.0
Optimize runs a default PRAGMA OPTIMIZE on the database. If it's the first time this function is called on this database, it will run a full optimization.
func (*DB) OptimizeWithMask ¶ added in v8.30.0
OptimizeWithMask runs a PRAGMA OPTIMIZE on the database, using the given mask.
func (*DB) QueryStringStmt ¶
QueryStringStmt executes a single query that return rows, but don't modify database.
func (*DB) QueryStringStmtWithTimeout ¶ added in v8.19.0
func (db *DB) QueryStringStmtWithTimeout(query string, tx bool, timeout time.Duration) ([]*command.QueryRows, error)
QueryStringStmtWithTimeout executes a single query that return rows, but don't modify database. It also sets a timeout for the query.
func (*DB) RegisterCommitHook ¶ added in v8.36.17
func (db *DB) RegisterCommitHook(hook CommitHookCallback) error
RegisterCommitHook registers a callback that is called whenever a transaction is committed to the database. If a callback is already registered, it is replaced. If hook is nil, the callback is removed.
func (*DB) RegisterPreUpdateHook ¶ added in v8.36.7
func (db *DB) RegisterPreUpdateHook(hook PreUpdateHookCallback, rowIDsOnly bool) error
RegisterPreUpdateHook registers a callback that is called before a row is modified in the database. If a callback is already registered, it is replaced. If hook is nil, the callback is removed.
func (*DB) RegisterUpdateHook ¶ added in v8.36.17
func (db *DB) RegisterUpdateHook(hook UpdateHookCallback) error
RegisterUpdateHook registers a callback that is called when a row is modified in the database. If a callback is already registered, it is replaced. If hook is nil, the callback is removed.
func (*DB) RequestStringStmts ¶
func (db *DB) RequestStringStmts(stmts []string) ([]*command.ExecuteQueryResponse, error)
RequestStringStmts processes a request that can contain both executes and queries.
func (*DB) RequestStringStmtsWithTimeout ¶ added in v8.19.0
func (db *DB) RequestStringStmtsWithTimeout(stmts []string, timeout time.Duration) ([]*command.ExecuteQueryResponse, error)
RequestStringStmtsWithTimeout processes a request that can contain both executes and queries.
func (*DB) Serialize ¶
Serialize returns a byte slice representation of the SQLite database. For an ordinary on-disk database file, the serialization is just a copy of the disk file. If the database is in WAL mode, a temporary on-disk copy is made, and it is this copy that is serialized. This function must not be called while any writes are happening to the database.
func (*DB) SetBusyTimeout ¶ added in v8.18.2
SetBusyTimeout sets the busy timeout for the database. If a timeout is is less than zero it is not set.
func (*DB) SetSynchronousMode ¶
func (db *DB) SetSynchronousMode(mode SynchronousMode) error
SetSynchronousMode sets the synchronous mode of the database.
func (*DB) Size ¶
Size returns the size of the database in bytes. "Size" is defined as page_count * schema.page_size.
func (*DB) StmtReadOnly ¶
StmtReadOnly returns whether the given SQL statement is read-only. As per https://www.sqlite.org/c3ref/stmt_readonly.html, this function may not return 100% correct results, but should cover most scenarios.
func (*DB) StmtReadOnlyWithConn ¶
StmtReadOnlyWithConn returns whether the given SQL statement is read-only, using the given connection.
func (*DB) VacuumInto ¶ added in v8.16.8
VacuumInto VACUUMs the database into the file at path
func (*DB) WALEnabled ¶
WALEnabled returns whether WAL mode is enabled.
func (*DB) WALLastModified ¶ added in v8.16.8
WALLastModified returns the last modified time of the WAL file.
type Driver ¶ added in v8.27.0
type Driver struct {
// contains filtered or unexported fields
}
Driver is a Database driver.
func CheckpointDriver ¶ added in v8.30.1
func CheckpointDriver() *Driver
CheckpointDriver returns the checkpoint driver. It registers the SQLite3 driver with the checkpoint driver name. It can be called multiple times, but only registers the SQLite3 driver once. This driver enables checkpoint on close for any database in WAL mode.
func DefaultDriver ¶ added in v8.27.0
func DefaultDriver() *Driver
DefaultDriver returns the default driver. It registers the SQLite3 driver with the default driver name. It can be called multiple times, but only registers the SQLite3 driver once. This driver disables checkpoint on close for any database in WAL mode.
func ForeignKeyDriver ¶ added in v8.36.4
func ForeignKeyDriver() *Driver
ForeignKeyDriver returns a driver that enables foreign key support on every connection.
func NewDriver ¶ added in v8.27.0
func NewDriver(name string, extensions []string, chkpt CnkOnCloseMode) *Driver
NewDriver returns a new driver with the given name and extensions. It registers the SQLite3 driver with the given name. extensions is a list of paths to SQLite3 extension shared objects. chkpt is the checkpoint-on-close mode the Driver will use.
If a driver with the given name already exists, a panic will occur.
func (*Driver) CheckpointOnCloseMode ¶ added in v8.30.1
func (d *Driver) CheckpointOnCloseMode() CnkOnCloseMode
CheckpointOnCloseMode returns the checkpoint on close mode.
func (*Driver) ExtensionNames ¶ added in v8.27.0
ExtensionNames returns the names of the loaded driver extensions.
func (*Driver) Extensions ¶ added in v8.27.0
Extensions returns the paths of the loaded driver extensions.
type PoolStats ¶
type PoolStats struct { MaxOpenConnections int `json:"max_open_connections"` OpenConnections int `json:"open_connections"` InUse int `json:"in_use"` Idle int `json:"idle"` WaitCount int64 `json:"wait_count"` WaitDuration time.Duration `json:"wait_duration"` MaxIdleClosed int64 `json:"max_idle_closed"` MaxIdleTimeClosed int64 `json:"max_idle_time_closed"` MaxLifetimeClosed int64 `json:"max_lifetime_closed"` }
PoolStats represents connection pool statistics
type PreUpdateHookCallback ¶ added in v8.36.7
PreUpdateHookCallback is a callback function that is called before a row is modified in the database.
type SwappableDB ¶ added in v8.17.0
type SwappableDB struct {
// contains filtered or unexported fields
}
SwappableDB is a wrapper around DB that allows the underlying database to be swapped out in a thread-safe manner.
func OpenSwappable ¶ added in v8.17.0
func OpenSwappable(dbPath string, drv *Driver, fkEnabled, wal bool) (*SwappableDB, error)
OpenSwappable returns a new SwappableDB instance, which opens the database at the given path, using the given driver. If drv is nil then the default driver is used. If fkEnabled is true, foreign key constraints are enabled. If wal is true, the WAL journal mode is enabled.
func (*SwappableDB) Backup ¶ added in v8.17.0
func (s *SwappableDB) Backup(path string, vacuum bool) error
Backup calls Backup on the underlying database.
func (*SwappableDB) Checkpoint ¶ added in v8.17.0
func (s *SwappableDB) Checkpoint(mode CheckpointMode) error
Checkpoint calls Checkpoint on the underlying database.
func (*SwappableDB) Close ¶ added in v8.17.0
func (s *SwappableDB) Close() error
Close closes the underlying database.
func (*SwappableDB) DBLastModified ¶ added in v8.31.1
func (s *SwappableDB) DBLastModified() (time.Time, error)
DBLastModified calls DBLastModified on the underlying database.
func (*SwappableDB) Dump ¶ added in v8.17.0
func (s *SwappableDB) Dump(w io.Writer) error
Dump calls Dump on the underlying database.
func (*SwappableDB) Execute ¶ added in v8.17.0
func (s *SwappableDB) Execute(ex *command.Request, xTime bool) ([]*command.ExecuteQueryResponse, error)
Execute calls Execute on the underlying database.
func (*SwappableDB) FKEnabled ¶ added in v8.17.0
func (s *SwappableDB) FKEnabled() bool
FKEnabled calls FKEnabled on the underlying database.
func (*SwappableDB) FileSize ¶ added in v8.24.0
func (s *SwappableDB) FileSize() (int64, error)
FileSize calls FileSize on the underlying database.
func (*SwappableDB) Optimize ¶ added in v8.30.0
func (s *SwappableDB) Optimize() error
Optimize calls Optimize on the underlying database.
func (*SwappableDB) Path ¶ added in v8.17.0
func (s *SwappableDB) Path() string
Path calls Path on the underlying database.
func (*SwappableDB) QueryStringStmt ¶ added in v8.17.0
func (s *SwappableDB) QueryStringStmt(query string) ([]*command.QueryRows, error)
QueryStringStmt calls QueryStringStmt on the underlying database.
func (*SwappableDB) Request ¶ added in v8.17.0
func (s *SwappableDB) Request(req *command.Request, xTime bool) ([]*command.ExecuteQueryResponse, error)
Request calls Request on the underlying database.
func (*SwappableDB) Serialize ¶ added in v8.17.0
func (s *SwappableDB) Serialize() ([]byte, error)
Serialize calls Serialize on the underlying database.
func (*SwappableDB) SetSynchronousMode ¶ added in v8.26.3
func (s *SwappableDB) SetSynchronousMode(mode SynchronousMode) error
SetSynchronousMode calls SetSynchronousMode on the underlying database.
func (*SwappableDB) Stats ¶ added in v8.17.0
func (s *SwappableDB) Stats() (map[string]interface{}, error)
Stats returns the underlying database's stats.
func (*SwappableDB) StmtReadOnly ¶ added in v8.17.0
func (s *SwappableDB) StmtReadOnly(sql string) (bool, error)
StmtReadOnly calls StmtReadOnly on the underlying database.
func (*SwappableDB) Swap ¶ added in v8.17.0
func (s *SwappableDB) Swap(path string, fkConstraints, walEnabled bool) error
Swap swaps the underlying database with that at the given path. The Swap operation may fail on some platforms if the file at path is open by another process. It is the caller's responsibility to ensure the file at path is not in use.
func (*SwappableDB) Vacuum ¶ added in v8.31.2
func (s *SwappableDB) Vacuum() error
Vacuum calls Vacuum on the underlying database.
func (*SwappableDB) VacuumInto ¶ added in v8.17.0
func (s *SwappableDB) VacuumInto(path string) error
VacuumInto calls VacuumInto on the underlying database.
func (*SwappableDB) WALEnabled ¶ added in v8.17.0
func (s *SwappableDB) WALEnabled() bool
WALEnabled calls WALEnabled on the underlying database.
func (*SwappableDB) WALSize ¶ added in v8.30.5
func (s *SwappableDB) WALSize() (int64, error)
WALSize calls WALSize on the underlying database.
type SynchronousMode ¶ added in v8.26.3
type SynchronousMode int
SynchronousMode is SQLite synchronous mode.
const ( SynchronousOff SynchronousMode = iota SynchronousNormal SynchronousFull SynchronousExtra )
func SynchronousModeFromInt ¶ added in v8.26.3
func SynchronousModeFromInt(i int) (SynchronousMode, error)
SynchronousModeFromInt returns the synchronous mode from the given integer.
func SynchronousModeFromString ¶ added in v8.26.3
func SynchronousModeFromString(s string) (SynchronousMode, error)
SynchronousModeFromString returns the synchronous mode from the given string.
func (SynchronousMode) String ¶ added in v8.26.3
func (s SynchronousMode) String() string
String returns the string representation of the synchronous mode.
type UpdateHookCallback ¶ added in v8.36.17
type UpdateHookCallback func(ev *command.UpdateHookEvent) error
UpdateHookCallback is a callback function that is called before a row is modified in the database.