Help us shape the future of Go! Take the 2026 Go Developer Survey

sqliteutil

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package sqliteutil provides shared SQLite health-check and recovery utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckAndRecover

func CheckAndRecover(db *sqlx.DB, dbPath string) (bool, error)

CheckAndRecover attempts to detect and fix stale WAL/SHM files that cause "disk I/O error" on SQLite databases using WAL journal mode. This happens when a process crashes or doesn't cleanly close its connection, leaving behind -shm and -wal files that reference invalid shared memory state.

Recovery strategy:

  1. Try to ping the database
  2. If that succeeds, run PRAGMA integrity_check as a deeper validation
  3. If either fails, close the connection, remove stale -shm/-wal files, and return an error indicating the caller should retry

Returns (healthy bool, error). If healthy is false and error is nil, stale files were removed and the caller should reopen the connection.

func CheckAndRecoverContext

func CheckAndRecoverContext(ctx context.Context, db *sqlx.DB, dbPath string) (bool, error)

CheckAndRecoverContext is like CheckAndRecover but respects context cancellation.

func OpenWithRecovery

func OpenWithRecovery(dbPath, dsn string) (*sqlx.DB, error)

OpenWithRecovery opens a SQLite database with the given DSN, performing health checks and automatic WAL recovery if stale files are detected. It will attempt recovery once before giving up.

func OpenWithRecoveryContext

func OpenWithRecoveryContext(ctx context.Context, dbPath, dsn string) (*sqlx.DB, error)

OpenWithRecoveryContext is like OpenWithRecovery but respects context cancellation and configures the connection pool for resilience after sleep/wake cycles.

Types

This section is empty.

Jump to

Keyboard shortcuts

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