table

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package table provides table management for XxSql storage engine.

Index

Constants

View Source
const (
	// MetaFileExt is the extension for table metadata files.
	MetaFileExt = ".xmeta"

	// DataFileExt is the extension for table data files.
	DataFileExt = ".xdb"

	// IndexFileExt is the extension for index files.
	IndexFileExt = ".xidx"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type IndexInfo

type IndexInfo struct {
	Name       string      `json:"name"`
	Columns    []string    `json:"columns"`
	Unique     bool        `json:"unique"`
	RootPageID page.PageID `json:"root_page_id"`
}

IndexInfo represents index metadata.

type Table

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

Table represents an open table.

func OpenTable

func OpenTable(dataDir, name string, columns []*types.ColumnInfo) (*Table, error)

OpenTable opens or creates a table.

func (*Table) AddCheckConstraint

func (t *Table) AddCheckConstraint(constraint *types.CheckConstraintInfo) error

AddCheckConstraint adds a single CHECK constraint to the table.

func (*Table) AddCheckConstraints

func (t *Table) AddCheckConstraints(constraints []*types.CheckConstraintInfo) error

AddCheckConstraints adds CHECK constraints to the table.

func (*Table) AddColumn

func (t *Table) AddColumn(col *types.ColumnInfo) error

AddColumn adds a column to the table.

func (*Table) AddForeignKey

func (t *Table) AddForeignKey(fk *types.ForeignKeyInfo) error

AddForeignKey adds a single FOREIGN KEY constraint to the table.

func (*Table) AddForeignKeys

func (t *Table) AddForeignKeys(fks []*types.ForeignKeyInfo) error

AddForeignKeys adds FOREIGN KEY constraints to the table.

func (*Table) AddUniqueConstraint

func (t *Table) AddUniqueConstraint(colName, constraintName string) error

AddUniqueConstraint adds a UNIQUE constraint to a column.

func (*Table) Close

func (t *Table) Close() error

Close closes the table.

func (*Table) Columns

func (t *Table) Columns() []*types.ColumnInfo

Columns returns the column definitions.

func (*Table) CreateIndex

func (t *Table) CreateIndex(name string, columns []string, unique bool) error

CreateIndex creates a new index on the table.

func (*Table) Delete

func (t *Table) Delete(predicate func(*row.Row) bool) (int, error)

Delete deletes rows that match the predicate.

func (*Table) Drop

func (t *Table) Drop() error

Drop drops the table.

func (*Table) DropCheckConstraint

func (t *Table) DropCheckConstraint(name string) error

DropCheckConstraint drops a CHECK constraint by name.

func (*Table) DropColumn

func (t *Table) DropColumn(colName string) error

DropColumn drops a column from the table.

func (*Table) DropForeignKey

func (t *Table) DropForeignKey(name string) error

DropForeignKey drops a FOREIGN KEY constraint by name.

func (*Table) DropIndex

func (t *Table) DropIndex(name string) error

DropIndex drops an index.

func (*Table) DropUniqueConstraint

func (t *Table) DropUniqueConstraint(constraintName string) error

DropUniqueConstraint drops a UNIQUE constraint by name.

func (*Table) FindByKey

func (t *Table) FindByKey(key types.Value) (*row.Row, error)

FindByKey finds a row by primary key.

func (*Table) Flush

func (t *Table) Flush() error

Flush flushes all dirty pages to disk.

func (*Table) GetCheckConstraints

func (t *Table) GetCheckConstraints() []*types.CheckConstraintInfo

GetCheckConstraints returns the CHECK constraints.

func (*Table) GetForeignKeys

func (t *Table) GetForeignKeys() []*types.ForeignKeyInfo

GetForeignKeys returns the FOREIGN KEY constraints.

func (*Table) GetIndexManager

func (t *Table) GetIndexManager() *btree.IndexManager

GetIndexManager returns the index manager.

func (*Table) GetInfo

func (t *Table) GetInfo() *TableInfo

GetInfo returns the table info.

func (*Table) Insert

func (t *Table) Insert(values []types.Value) (row.RowID, error)

Insert inserts a row into the table.

func (*Table) ModifyColumn

func (t *Table) ModifyColumn(col *types.ColumnInfo) error

ModifyColumn modifies a column definition.

func (*Table) Name

func (t *Table) Name() string

Name returns the table name.

func (*Table) Rename

func (t *Table) Rename(newName string) error

Rename renames the table.

func (*Table) RenameColumn

func (t *Table) RenameColumn(oldName, newName string) error

RenameColumn renames a column.

func (*Table) RowCount

func (t *Table) RowCount() uint64

RowCount returns the number of rows.

func (*Table) Scan

func (t *Table) Scan() ([]*row.Row, error)

Scan returns all rows in the table.

func (*Table) SetPrimaryKey

func (t *Table) SetPrimaryKey(colName string) error

SetPrimaryKey sets a column as primary key.

func (*Table) Truncate

func (t *Table) Truncate() error

Truncate removes all rows from the table.

func (*Table) Update

func (t *Table) Update(predicate func(*row.Row) bool, updates map[int]types.Value) (int, error)

Update updates rows that match the predicate.

type TableInfo

type TableInfo struct {
	Name             string                       `json:"name"`
	Columns          []*types.ColumnInfo          `json:"columns"`
	PrimaryKey       []string                     `json:"primary_key,omitempty"`
	Indexes          []*IndexInfo                 `json:"indexes,omitempty"`
	CheckConstraints []*types.CheckConstraintInfo `json:"check_constraints,omitempty"`
	ForeignKeys      []*types.ForeignKeyInfo      `json:"foreign_keys,omitempty"`
	CreatedAt        time.Time                    `json:"created_at"`
	ModifiedAt       time.Time                    `json:"modified_at"`
	RowCount         uint64                       `json:"row_count"`
	NextRowID        uint64                       `json:"next_row_id"`
	NextPageID       page.PageID                  `json:"next_page_id"`
	RootPageID       page.PageID                  `json:"root_page_id"`
	State            TableState                   `json:"state"`
}

TableInfo represents table metadata.

type TableState

type TableState uint8

TableState represents the state of a table.

const (
	TableStateActive TableState = iota
	TableStateDeleting
	TableStateDeleted
)

Jump to

Keyboard shortcuts

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