sqlite

package
v0.0.0-...-d4756b9 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BTreePage

type BTreePage struct {
	PageNumber         uint32
	Raw                []byte
	UsablePageBytes    uint16
	PageHeader         PageHeader
	CellPointerArray   CellPointerArray
	TableLeafCells     []TableLeafCell
	TableInteriorCells []TableInteriorCell
	IndexLeafCells     []IndexLeafCell
	IndexInteriorCells []IndexInteriorCell
	Freeblocks         []Freeblock
	UnallocatedRegions []UnallocatedRegion
}

func (*BTreePage) BytesFor

func (p *BTreePage) BytesFor(meta Meta) []byte

type CellPointerArray

type CellPointerArray struct {
	Meta     Meta
	Pointers []Uint16Field
}

type DBHeader

type DBHeader struct {
	HeaderString              string
	PageSize                  uint32
	WriteVersion              uint8
	ReadVersion               uint8
	ReservedBytesPerPage      uint8
	MaxEmbeddedPayloadFrac    uint8
	MinEmbeddedPayloadFrac    uint8
	LeafPayloadFrac           uint8
	FileChangeCounter         uint32
	DatabasePageCount         uint32
	FirstFreelistTrunkPage    uint32
	FreelistPageCount         uint32
	SchemaCookie              uint32
	SchemaFormat              uint32
	SuggestedCacheSize        int32
	AutoVacuumLargestRootPage uint32
	TextEncoding              uint32
	UserVersion               uint32
	IncrementalVacuum         uint32
	ApplicationID             uint32
	ReservedForExpansion      [20]byte
	VersionValidFor           uint32
	SQLiteVersionNumber       uint32
}

DBHeader mirrors the 100-byte SQLite database header at file offset 0. Field order and types map directly to https://sqlite.org/fileformat.html.

type Freeblock

type Freeblock struct {
	Meta          Meta
	NextFreeblock Uint16Field
}

type IndexInteriorCell

type IndexInteriorCell struct {
	Meta          Meta
	LeftChildPage Uint32Field
	PayloadSize   VarintField
	ParsedPayload *RecordPayload
}

type IndexLeafCell

type IndexLeafCell struct {
	Meta          Meta
	PayloadSize   VarintField
	ParsedPayload *RecordPayload
}

type Inspector

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

func Open

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

func (*Inspector) Close

func (i *Inspector) Close() error

func (*Inspector) InspectDatabaseMetadata

func (i *Inspector) InspectDatabaseMetadata() (*MetadataInspection, error)

func (*Inspector) InspectPage

func (i *Inspector) InspectPage(number uint32) (*PageInspection, error)

func (*Inspector) PagesForRoot

func (i *Inspector) PagesForRoot(root uint32) (PageWalk, error)

PagesForRoot walks the b-tree rooted at `root` and returns every page in it (interior + leaf nodes reachable from the root).

  • Per-child parse failures are recorded in PageWalk.Skipped and the walk continues (degrade, don't crash).
  • An error is returned ONLY for a hard failure: an invalid root, or the root page itself being unreadable.
  • root == 0 (e.g. virtual tables with no b-tree) returns an empty PageWalk and no error.

Overflow-page chains are intentionally not followed; an index is its own b-tree and must be walked from its own root.

type Meta

type Meta struct {
	StartOffset int
	Size        int
}

func (Meta) EndOffset

func (m Meta) EndOffset() int

func (Meta) FileEndOffset

func (m Meta) FileEndOffset(pageNumber uint32, pageSize uint32) int64

func (Meta) FileStartOffset

func (m Meta) FileStartOffset(pageNumber uint32, pageSize uint32) int64

func (Meta) Valid

func (m Meta) Valid() bool

type MetadataInspection

type MetadataInspection struct {
	Path          string
	DBHeader      DBHeader
	SchemaRecords []Row
}
type PageHeader struct {
	Meta                  Meta
	PageKind              PageKindField
	FirstFreeblock        Uint16Field
	CellCount             Uint16Field
	CellContentAreaOffset Uint16Field
	FragmentedFreeBytes   Uint8Field
	RightMostPointer      *Uint32Field
}

func (*PageHeader) HeaderSize

func (h *PageHeader) HeaderSize() int

func (*PageHeader) IsInterior

func (h *PageHeader) IsInterior() bool

type PageIndex

type PageIndex struct {
	Walks map[uint32]PageWalk // keyed by PageWalk.Root
}

PageIndex maps each b-tree root page to the walk that enumerated it. It is plain data (PageWalk is itself serializable), so the whole index can later be persisted to / restored from disk. Build it from a single goroutine (the TUI Update loop); the walks it stores are produced in parallel upstream by PagesForRoot.

func NewPageIndex

func NewPageIndex() PageIndex

NewPageIndex returns an empty index ready to accept walks.

func (PageIndex) Pages

func (idx PageIndex) Pages(root uint32) []uint32

Pages returns the page set for root, or nil if not indexed. Convenience for callers that only want the page numbers (the filtered PAGES list).

func (PageIndex) Set

func (idx PageIndex) Set(walk PageWalk)

Set stores (or replaces) the walk for walk.Root.

The value receiver mutates the underlying map (maps are reference types), which is intentional and matches Go idiom for map-backed wrappers.

func (PageIndex) Walk

func (idx PageIndex) Walk(root uint32) (PageWalk, bool)

Walk returns the stored walk for root and whether it is present (indexed yet).

type PageInspection

type PageInspection struct {
	PageNumber uint32
	DBHeader   *DBHeader
	BTreePage  BTreePage
}

type PageKindField

type PageKindField struct {
	Meta  Meta
	Value PageKindType
}

type PageKindType

type PageKindType int8
const (
	InteriorIndexBTreePage PageKindType = 0x02
	InteriorTableBTreePage PageKindType = 0x05
	LeafIndexBTreePage     PageKindType = 0x0a
	LeafTableBTreePage     PageKindType = 0x0d
)

type PageWalk

type PageWalk struct {
	Root    uint32        // the root page the walk started from
	Pages   []uint32      // sorted, unique; includes Root; only pages actually reached
	Skipped []SkippedPage // child pages that could not be parsed (degraded walk)
}

PageWalk is the result of walking one b-tree from its root. Serializable by design (plain integers) so it can later be persisted to disk.

type RecordColumn

type RecordColumn struct {
	Meta       Meta
	SerialType uint64
	Value      any
}

type RecordPayload

type RecordPayload struct {
	Meta              Meta
	HeaderSize        VarintField
	SerialTypes       []VarintField
	Columns           []RecordColumn
	OverflowFirstPage *Uint32Field
}

type Row

type Row map[string]any

func ParseRecord

func ParseRecord(record *RecordPayload, definition *SchemaDefinition) (Row, error)

type SchemaDefinition

type SchemaDefinition struct {
	Fields []SchemaField
}

func ParseSchemaDefinitionSQL

func ParseSchemaDefinitionSQL(sql string) (*SchemaDefinition, error)

type SchemaField

type SchemaField struct {
	Name         string
	DeclaredType string
	Expression   string
}

type SkippedPage

type SkippedPage struct {
	Page   uint32 // the unreadable child page
	Parent uint32 // the interior page that pointed to it
	Reason string // human-readable parse error
}

SkippedPage records a child pointer that failed to parse during the walk.

type TableInteriorCell

type TableInteriorCell struct {
	Meta          Meta
	LeftChildPage Uint32Field
	RowID         VarintField
}

type TableLeafCell

type TableLeafCell struct {
	Meta          Meta
	PayloadSize   VarintField
	RowID         VarintField
	ParsedPayload *RecordPayload
}

type Uint8Field

type Uint8Field struct {
	Meta  Meta
	Value uint8
}

type Uint16Field

type Uint16Field struct {
	Meta  Meta
	Value uint16
}

type Uint32Field

type Uint32Field struct {
	Meta  Meta
	Value uint32
}

type Uint64Field

type Uint64Field struct {
	Meta  Meta
	Value uint64
}

type UnallocatedRegion

type UnallocatedRegion struct {
	Meta Meta
}

type VarintField

type VarintField struct {
	Meta  Meta
	Value uint64
}

Jump to

Keyboard shortcuts

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