sqlitepool

package
v0.2.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package sqlitepool keeps one database handle per SQLite file and access mode for the life of a process, for callers that open the file for each operation. A process turns it on once (Enable); until then Acquire opens a new handle for every caller and closes it on release, as those callers did before. Test binaries leave it off, so nothing keeps their temporary directories' files open (Windows cannot delete an open file).

A kept handle is reused only while the path still names the file it was opened on, with the same mode: a database deleted, replaced by another file or made read-only is opened again, never read or written through the old handle. A handle nobody used for idleTimeout is closed. A file rewritten in place by something other than SQLite is not noticed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Acquire

func Acquire(path string, readOnly bool, open func() (db *sql.DB, keep bool, err error)) (*sql.DB, func(), error)

Acquire returns a handle for the SQLite file at path, opened by open when none is kept, and the function that releases it. The handle is shared: callers must not close it, change its pool settings or leave a transaction open past release. A path that does not exist (yet) is opened and closed again on release, never kept; so is a handle open reports not to keep (keep false).

func CloseIdle

func CloseIdle(after time.Duration)

CloseIdle closes the kept handles unused for at least after; 0 closes every handle not in use now, and the others when they are released.

func CloseUnder

func CloseUnder(dir string)

CloseUnder closes the kept handles of files under dir: now those not in use, the others at their last release. A caller removing dir calls it first, since an open file cannot be removed on Windows.

func Disable

func Disable()

Disable closes every kept handle not in use, and the others when they are released, and stops keeping them. For tests.

func Enable

func Enable()

Enable keeps handles open from now on. The daemon and the command line call it once at startup.

func Enabled

func Enabled() bool

Enabled reports whether handles are kept.

func WALSupported

func WALSupported(dir string) bool

WALSupported reports whether SQLite's write-ahead log works in dir: a scratch database there is switched to WAL, written and read back, then removed. The log's -shm index is memory-mapped, which some file systems (FUSE mounts, some network and VM shares) refuse; a database switched to WAL there could not be opened again, by this binary or an older one. The answer is kept per directory for the life of the process.

Types

This section is empty.

Jump to

Keyboard shortcuts

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