Documentation
¶
Index ¶
- type BTreePage
- type CellPointerArray
- type DBHeader
- type Freeblock
- type IndexInteriorCell
- type IndexLeafCell
- type Inspector
- type Meta
- type MetadataInspection
- type PageHeader
- type PageIndex
- type PageInspection
- type PageKindField
- type PageKindType
- type PageWalk
- type RecordColumn
- type RecordPayload
- type Row
- type SchemaDefinition
- type SchemaField
- type SkippedPage
- type TableInteriorCell
- type TableLeafCell
- type Uint8Field
- type Uint16Field
- type Uint32Field
- type Uint64Field
- type UnallocatedRegion
- type VarintField
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
}
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 (*Inspector) InspectDatabaseMetadata ¶
func (i *Inspector) InspectDatabaseMetadata() (*MetadataInspection, error)
func (*Inspector) InspectPage ¶
func (i *Inspector) InspectPage(number uint32) (*PageInspection, error)
func (*Inspector) PagesForRoot ¶
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 ¶
func (Meta) FileStartOffset ¶
type MetadataInspection ¶
type PageHeader ¶
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 ¶
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 ¶
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).
type PageInspection ¶
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 RecordPayload ¶
type RecordPayload struct {
Meta Meta
HeaderSize VarintField
SerialTypes []VarintField
Columns []RecordColumn
OverflowFirstPage *Uint32Field
}
type Row ¶
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 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 Uint16Field ¶
type Uint32Field ¶
type Uint64Field ¶
type UnallocatedRegion ¶
type UnallocatedRegion struct {
Meta Meta
}