sqliteread

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package sqliteread reads local SQLite stores that agents keep their session data in — today, Cursor's `state.vscdb` chat store.

It is a thin read-only layer over modernc.org/sqlite, a pure-Go SQLite that keeps the platform's CGO_ENABLED=0 builds working. The package exists to concentrate the rules for touching someone's live editor database in one place:

  • Stores are opened with the URI parameter `mode=ro`, so SQLite refuses every write to the store. A store being read while Cursor is running is the normal case, and WAL-mode SQLite serves concurrent readers.
  • A write-ahead log is applied, so rows Cursor has not checkpointed yet are visible. This is why `mode=ro` is used rather than `immutable=1`, which would ignore the log and quietly report stale data.
  • Opening a WAL-mode store makes SQLite create a `<path>-shm` coordination file beside it when none exists. That file is ephemeral bookkeeping, not a change to the store; the store itself is never modified.
  • If the store cannot be opened in place at all — a read-only directory, say — it is copied to a temporary file and the copy is read instead, so the answer stays correct rather than silently degrading.

The surface is deliberately small: list the tables, scan one wholly or by an indexed text prefix. Callers get decoded rows and do their own interpretation.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotSQLite = errors.New("not a SQLite database file")

ErrNotSQLite reports a file that does not carry the SQLite header magic.

View Source
var ErrStopScan = errors.New("stop scan")

ErrStopScan ends a Scan early without reporting an error.

Functions

This section is empty.

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB is an open read-only SQLite store.

func Open

func Open(path string) (*DB, error)

Open opens the store at path for reading and loads its schema.

func (*DB) Close

func (db *DB) Close() error

Close releases the store and removes any temporary copy.

func (*DB) Scan

func (db *DB) Scan(name string, fn func(Row) error) error

Scan calls fn for every row of the named table. Scanning stops and the error is returned when fn returns one; returning ErrStopScan stops without an error.

func (*DB) ScanPrefix

func (db *DB) ScanPrefix(name, column, prefix string, fn func(Row) error) error

ScanPrefix calls fn for rows whose named text column starts with prefix. The range predicate lets SQLite use the column's index instead of scanning the entire table. The column and table must both exist in the loaded schema.

func (*DB) Table

func (db *DB) Table(name string) (Table, bool)

Table looks up one table by name, case-insensitively as SQLite does.

func (*DB) Tables

func (db *DB) Tables() []Table

Tables returns the schema's tables, in sqlite_master order. SQLite's own internal tables are omitted.

type Row

type Row struct {
	Columns []string
	Values  []Value
	// RowID is the row's integer key, set only for rowid tables.
	RowID int64
}

Row is one decoded row. Values is positional and parallel to Columns.

func (Row) Text

func (r Row) Text(column string) (string, bool)

Text returns the named column as a string, decoding BLOB values as bytes. It reports false when the column is missing or holds NULL.

func (Row) Value

func (r Row) Value(column string) (Value, bool)

Value returns the value of the named column.

type Table

type Table struct {
	Name string
	// SQL is the CREATE statement as stored in sqlite_master.
	SQL string
	// Columns are the declared column names, in declaration order.
	Columns []string
}

Table is one table in the schema.

type Value

type Value = any

Value is one decoded column value: nil, int64, float64, string, or []byte. It is an alias rather than a named type so that database/sql can scan directly into it, which it only does for a plain any.

Jump to

Keyboard shortcuts

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