storage

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package storage provides the storage engine for XxSql.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseColumnDefs

func ParseColumnDefs(defs []struct {
	Name     string
	Type     string
	Size     int
	Nullable bool
	Default  interface{}
	Primary  bool
	AutoIncr bool
}) []*types.ColumnInfo

ParseColumnDefs parses SQL column definitions to storage types.

func ValidateValues

func ValidateValues(columns []*types.ColumnInfo, values []types.Value) error

ValidateValues validates values against column definitions.

Types

type Engine

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

Engine represents the storage engine.

func NewEngine

func NewEngine(dataDir string) *Engine

NewEngine creates a new storage engine.

func (*Engine) BeginTransaction added in v0.0.5

func (e *Engine) BeginTransaction() error

BeginTransaction starts a new transaction. For this implementation, we track transaction state in memory. Full rollback support would require WAL replay.

func (*Engine) ClearTempTables added in v0.0.5

func (e *Engine) ClearTempTables()

ClearTempTables clears all temporary tables. Called when session ends.

func (*Engine) Close

func (e *Engine) Close() error

Close closes the storage engine.

func (*Engine) CommitTransaction added in v0.0.5

func (e *Engine) CommitTransaction() error

CommitTransaction commits the current transaction.

func (*Engine) CreateIndex

func (e *Engine) CreateIndex(tableName, indexName string, columns []string, unique bool) error

CreateIndex creates an index on a table.

func (*Engine) CreateSavepoint added in v0.0.5

func (e *Engine) CreateSavepoint(name string) error

CreateSavepoint creates a savepoint within the current transaction.

func (*Engine) CreateTable

func (e *Engine) CreateTable(name string, columns []*types.ColumnInfo) error

CreateTable creates a new table.

func (*Engine) CreateTempTable added in v0.0.5

func (e *Engine) CreateTempTable(name string, columns []*types.ColumnInfo) error

CreateTempTable creates a temporary table. Temp tables are session-scoped and not persisted to disk. A temp table can shadow a regular table with the same name.

func (*Engine) CreateTrigger added in v0.0.5

func (e *Engine) CreateTrigger(name string, timing, event int, tableName string, granularity int, whenClause, body string) error

CreateTrigger creates a new trigger.

func (*Engine) CreateView added in v0.0.5

func (e *Engine) CreateView(name, query string, columns []string, checkOption string) error

CreateView creates a new view.

func (*Engine) DropIndex

func (e *Engine) DropIndex(tableName, indexName string) error

DropIndex drops an index from a table.

func (*Engine) DropTable

func (e *Engine) DropTable(name string) error

DropTable drops a table.

func (*Engine) DropTableOrTemp added in v0.0.5

func (e *Engine) DropTableOrTemp(name string) error

DropTableOrTemp drops a table (regular or temp).

func (*Engine) DropTempTable added in v0.0.5

func (e *Engine) DropTempTable(name string) error

DropTempTable drops a temporary table.

func (*Engine) DropTrigger added in v0.0.5

func (e *Engine) DropTrigger(name string) error

DropTrigger drops a trigger.

func (*Engine) DropView added in v0.0.5

func (e *Engine) DropView(name string) error

DropView drops a view.

func (*Engine) EstimateSelectivity added in v0.0.5

func (e *Engine) EstimateSelectivity(tableName, indexName string) int

EstimateSelectivity estimates the selectivity of an index scan.

func (*Engine) Flush

func (e *Engine) Flush() error

Flush flushes all data to disk.

func (*Engine) GetCatalog

func (e *Engine) GetCatalog() *catalog.Catalog

GetCatalog returns the catalog.

func (*Engine) GetDataDir

func (e *Engine) GetDataDir() string

GetDataDir returns the data directory path.

func (*Engine) GetFTSManager added in v0.0.5

func (e *Engine) GetFTSManager() *fts.FTSManager

GetFTSManager returns the FTS manager.

func (*Engine) GetIndexForColumn added in v0.0.5

func (e *Engine) GetIndexForColumn(tableName, columnName string) (string, bool)

GetIndexForColumn returns the best index for a column.

func (*Engine) GetIndexForColumns added in v0.0.5

func (e *Engine) GetIndexForColumns(tableName string, columns []string) (string, bool, int)

GetIndexForColumns returns the best index for multiple columns.

func (*Engine) GetRowsByRowIDs added in v0.0.5

func (e *Engine) GetRowsByRowIDs(tableName string, rowIDs []row.RowID) (map[row.RowID]*row.Row, error)

GetRowsByRowIDs fetches rows by their row IDs.

func (*Engine) GetTable

func (e *Engine) GetTable(name string) (*table.Table, error)

GetTable returns a table by name.

func (*Engine) GetTableOrTemp added in v0.0.5

func (e *Engine) GetTableOrTemp(name string) (*table.Table, bool, error)

GetTableOrTemp returns a table by name, checking both regular and temp tables. Temp tables have priority over regular tables with the same name.

func (*Engine) GetTempTable added in v0.0.5

func (e *Engine) GetTempTable(name string) (*table.Table, error)

GetTempTable returns a temporary table by name.

func (*Engine) GetTrigger added in v0.0.5

func (e *Engine) GetTrigger(name string) (*catalog.TriggerInfo, error)

GetTrigger returns a trigger by name.

func (*Engine) GetTriggersForTable added in v0.0.5

func (e *Engine) GetTriggersForTable(tableName string, event int) []*catalog.TriggerInfo

GetTriggersForTable returns all triggers for a specific table and event.

func (*Engine) GetView added in v0.0.5

func (e *Engine) GetView(name string) (*catalog.ViewInfo, error)

GetView returns a view by name.

func (*Engine) IndexPointLookup added in v0.0.5

func (e *Engine) IndexPointLookup(tableName, indexName string, value types.Value) ([]row.RowID, error)

IndexPointLookup performs an index point lookup.

func (*Engine) IndexRangeScan added in v0.0.5

func (e *Engine) IndexRangeScan(tableName, indexName string, startValue, endValue types.Value, includeStart, includeEnd bool) ([]row.RowID, error)

IndexRangeScan performs an index range scan.

func (*Engine) Insert

func (e *Engine) Insert(tableName string, values []types.Value) (row.RowID, error)

Insert inserts a row into a table.

func (*Engine) ListTables

func (e *Engine) ListTables() []string

ListTables returns all table names.

func (*Engine) ListTempTables added in v0.0.5

func (e *Engine) ListTempTables() []string

ListTempTables returns all temporary table names.

func (*Engine) ListTriggers added in v0.0.5

func (e *Engine) ListTriggers() []string

ListTriggers returns all trigger names.

func (*Engine) ListViews added in v0.0.5

func (e *Engine) ListViews() []string

ListViews returns all view names.

func (*Engine) Open

func (e *Engine) Open() error

Open opens the storage engine.

func (*Engine) ReleaseSavepoint added in v0.0.5

func (e *Engine) ReleaseSavepoint(name string) error

ReleaseSavepoint releases a savepoint within the current transaction.

func (*Engine) RenameTable

func (e *Engine) RenameTable(oldName, newName string) error

RenameTable renames a table.

func (*Engine) ResetToInitialState added in v0.0.7

func (e *Engine) ResetToInitialState(dataDir string) map[string]interface{}

ResetToInitialState resets the server to its initial state. It drops all user tables (keeping _sys_ms, _sys_projects), clears _sys_projects, and deletes all files in the projects/ directory. Returns a map with details about what was reset.

func (*Engine) RollbackToSavepoint added in v0.0.5

func (e *Engine) RollbackToSavepoint(name string) error

RollbackToSavepoint rolls back to a savepoint within the current transaction. Note: This is a simplified implementation. Full savepoint rollback would require tracking changes since the savepoint and undoing them.

func (*Engine) RollbackTransaction added in v0.0.5

func (e *Engine) RollbackTransaction() error

RollbackTransaction rolls back the current transaction. Note: This is a simplified implementation. Full rollback would require WAL replay to restore the state before the transaction started.

func (*Engine) Scan

func (e *Engine) Scan(tableName string) ([]*row.Row, error)

Scan scans all rows from a table.

func (*Engine) Stats

func (e *Engine) Stats() *Stats

Stats returns storage engine statistics.

func (*Engine) TableExists

func (e *Engine) TableExists(name string) bool

TableExists checks if a table exists.

func (*Engine) TableOrTempExists added in v0.0.5

func (e *Engine) TableOrTempExists(name string) bool

TableOrTempExists checks if a table exists (regular or temp).

func (*Engine) TempTableExists added in v0.0.5

func (e *Engine) TempTableExists(name string) bool

TempTableExists checks if a temporary table exists.

func (*Engine) TriggerExists added in v0.0.5

func (e *Engine) TriggerExists(name string) bool

TriggerExists checks if a trigger exists.

func (*Engine) ViewExists added in v0.0.5

func (e *Engine) ViewExists(name string) bool

ViewExists checks if a view exists.

type Stats

type Stats struct {
	TableCount int          `json:"table_count"`
	Tables     []TableStats `json:"tables"`
}

Stats represents storage engine statistics.

type TableStats

type TableStats struct {
	Name      string `json:"name"`
	RowCount  uint64 `json:"row_count"`
	PageCount int    `json:"page_count"`
}

TableStats represents table statistics.

type TransactionState added in v0.0.5

type TransactionState struct {
	ID         uint64
	Active     bool
	Savepoints []string
}

TransactionState tracks the state of a transaction

Directories

Path Synopsis
Package btree provides B+ tree index implementation for XxSql.
Package btree provides B+ tree index implementation for XxSql.
Package buffer provides buffer pool management for XxSql storage engine.
Package buffer provides buffer pool management for XxSql storage engine.
Package catalog provides catalog management for XxSql storage engine.
Package catalog provides catalog management for XxSql storage engine.
Package checkpoint provides checkpoint management for XxSql storage engine.
Package checkpoint provides checkpoint management for XxSql storage engine.
Package fts provides full-text search functionality for XxSQL.
Package fts provides full-text search functionality for XxSQL.
Package lock provides deadlock detection for XxSql storage engine.
Package lock provides deadlock detection for XxSql storage engine.
Package page provides page management for XxSql storage engine.
Package page provides page management for XxSql storage engine.
Package recovery provides crash recovery for XxSql storage engine.
Package recovery provides crash recovery for XxSql storage engine.
Package row provides row serialization for XxSql storage engine.
Package row provides row serialization for XxSql storage engine.
Package sequence provides atomic sequence counters for XxSql.
Package sequence provides atomic sequence counters for XxSql.
Package table provides table management for XxSql storage engine.
Package table provides table management for XxSql storage engine.
Package types provides data type definitions for XxSql storage engine.
Package types provides data type definitions for XxSql storage engine.
Package wal provides Write-Ahead Logging for XxSql storage engine.
Package wal provides Write-Ahead Logging for XxSql storage engine.

Jump to

Keyboard shortcuts

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