Documentation
¶
Overview ¶
Package sqlite opens OpenCode's database, opencode.db, and reads its rows as the opencode package's types: the V1 tables session, message and part, and the V2 tables session_v2, session_message, session_pending and session_inbox. It is the one package of this module that imports a database driver, modernc.org/sqlite, a SQLite written in Go, so the opencode package stays on the standard library alone.
The database is never opened in place: Open reads a private copy of it and its write-ahead log, which internal/sqlite makes and checks against OpenCode writing to it while it copies, as clinesdk/sqlite does Cline's. Frames appended to the log while it was copied are ones SQLite's recovery reads up to the last commit it finds whole.
Index ¶
- Variables
- func Fixture(path, script string) (io.Closer, error)
- func OpenStore(path string) (opencode.Database, error)
- func Probe(path string) bool
- func RemoveCopies()
- type DB
- func (d *DB) Close() error
- func (d *DB) Has(table string) bool
- func (d *DB) IsOpenCode() bool
- func (d *DB) Messages(s *opencode.Session) ([]*opencode.MessageRecord, []*opencode.Stray, error)
- func (d *DB) MigrationDone() bool
- func (d *DB) Name() string
- func (d *DB) Orphans(map[string]bool) ([]*opencode.Stray, error)
- func (d *DB) Project(id string) (opencode.Project, bool)
- func (d *DB) Rows(s *opencode.Session) ([]*opencode.Row2, []*opencode.QueueRow, error)
- func (d *DB) Sessions() ([]*opencode.Session, []*opencode.Stray, error)
- func (d *DB) Units() (int, error)
Constants ¶
This section is empty.
Variables ¶
var ErrBusy = errors.New("the database kept changing while it was copied; OpenCode may be running, try again when it is idle")
ErrBusy is returned by Open when the database kept changing while it was copied: OpenCode is writing to it.
var ErrNotOpenCode = errors.New("the database holds none of OpenCode's session tables (session, message and part, or session_v2 and session_message); Crush's opencode.db is another program's")
ErrNotOpenCode is returned by Open for a database that holds none of OpenCode's session tables, such as Crush's (opencode-ai/opencode), whose tables are sessions and messages.
Functions ¶
func Fixture ¶
Fixture builds a database at path from SQL text, for tests: the fixtures of this module are SQL text, never database files. The database is put in WAL mode with automatic checkpoints off and returned open: rows the script writes after a checkpoint stay in the write-ahead log, where a reader finds them only through the log, for as long as the returned closer is not closed. Closing it checkpoints the log into the database.
func OpenStore ¶
OpenStore is Open as the opencode/convert package takes it, in its Options.OpenDatabase.
func Probe ¶
Probe reports whether the file at path is an OpenCode database, reading its schema without copying it: the file is opened immutable, which takes no lock and writes nothing beside it, and reads what has been checkpointed into it, where OpenCode's tables are from the database's first start.
func RemoveCopies ¶
func RemoveCopies()
RemoveCopies removes the copy of every database open: what a program interrupted while it reads one calls before it exits, as a deferred Close does not run then. The copies are in os.TempDir, under $TMPDIR when it is set.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is a copy of an OpenCode database, open for reading. It implements opencode.Store. A DB is not safe for concurrent use.
func (*DB) IsOpenCode ¶
IsOpenCode reports whether the database holds OpenCode's V1 or V2 session tables.
func (*DB) MigrationDone ¶
MigrationDone reports whether OpenCode 2 recorded its copy of the V1 tables complete, in kv's migration.v1-v2.
func (*DB) Orphans ¶
Orphans lists the message rows of no session of the V1 tables, the part rows of no message read with one, and the session_message, session_pending and session_inbox rows of no session of the V2 tables. sessions is not read: every row of a session is read with it, so a row is an orphan when its session row does not exist. A V1 database's own session_message, OpenCode 1's projection of its messages, which no V1 request reads, is reported once, its rows not records.