sql

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Overview

Package sql provides the public API for the GSQL database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecSQL

func ExecSQL(db *DB, sql string) (string, error)

ExecSQL executes SQL and returns result as string.

func Version

func Version() string

Version returns the database version.

Types

type Column

type Column struct {
	Name string
	Type string
}

Column type for CreateTable compatibility.

type Config

type Config struct {
	VFS       *vfs.VFS
	PageSize  int
	CacheSize int
}

Config holds database configuration.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default configuration.

type DB

type DB struct {
	VFS      *vfs.VFS
	File     vfs.File
	Pager    *pager.Pager
	BTree    *btree.Btree
	Schema   *schema.Schema
	InTrans  bool
	LastID   int64
	Changes  int64
	IsMemory bool
	Tables   map[string]interface{} // In-memory table storage (schema cache)

	// Savepoint tracking
	SavepointName string
}

DB represents a database connection.

func Open

func Open(filename string, config *Config) (*DB, error)

Open opens a database file. If filename is ":memory:" or starts with "mem", an in-memory database is used. Otherwise, a persistent database file is created/opened.

func (*DB) Begin

func (db *DB) Begin() error

Begin begins a transaction.

func (*DB) Close

func (db *DB) Close() error

Close closes the database.

func (*DB) Commit

func (db *DB) Commit() error

Commit commits the current transaction.

func (*DB) CreateIndex

func (db *DB) CreateIndex(name, table string, cols []string, unique bool) error

CreateIndex is no-op for compatibility (use Exec with CREATE INDEX SQL).

func (*DB) CreateTable

func (db *DB) CreateTable(name string, cols []*Column) error

CreateTable is no-op for compatibility (use Exec with CREATE TABLE SQL).

func (*DB) DropIndex

func (db *DB) DropIndex(name string) error

DropIndex is no-op for compatibility (use Exec with DROP INDEX SQL).

func (*DB) DropTable

func (db *DB) DropTable(name string) error

DropTable is no-op for compatibility (use Exec with DROP TABLE SQL).

func (*DB) Exec

func (db *DB) Exec(sql string) (int64, error)

Exec executes SQL and returns affected rows.

func (*DB) Flush

func (db *DB) Flush() error

Flush flushes any pending writes to persistent storage.

func (*DB) GetBTree

func (db *DB) GetBTree() interface{}

GetBTree implements codegen.DB interface.

func (*DB) GetIndex

func (db *DB) GetIndex(name string) *schema.Index

GetIndex looks up an index by name (implements vdbe.DB interface).

func (*DB) GetSchema

func (db *DB) GetSchema() *schema.Schema

GetSchema returns the database schema (implements codegen.DB interface).

func (*DB) GetTable

func (db *DB) GetTable(name string) *schema.Table

GetTable looks up a table by name (implements vdbe.DB interface).

func (*DB) GetTableData

func (db *DB) GetTableData(name string) interface{}

GetTableData gets table data by name (implements vdbe.DB interface).

func (*DB) Prepare

func (db *DB) Prepare(sql string) (*Stmt, error)

Prepare prepares an SQL statement.

func (*DB) Query

func (db *DB) Query(sql string) (*Stmt, error)

Query executes SQL and returns a result iterator.

func (*DB) Rollback

func (db *DB) Rollback() error

Rollback rolls back the current transaction.

func (*DB) SetTableData

func (db *DB) SetTableData(name string, data interface{})

SetTableData sets table data by name (implements vdbe.DB interface).

func (*DB) Table

func (db *DB) Table(name string) interface{}

Table returns nil (schema info not available without BTree integration).

type Stmt

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

Stmt represents a prepared statement.

func (*Stmt) Bind

func (s *Stmt) Bind(idx int, value interface{}) error

Bind binds a value to a parameter.

func (*Stmt) Column

func (s *Stmt) Column(idx int) (interface{}, error)

Column returns the value of a column.

func (*Stmt) ColumnCount

func (s *Stmt) ColumnCount() int

ColumnCount returns the number of columns in the result.

func (*Stmt) Finalize

func (s *Stmt) Finalize() error

Finalize finalizes the statement.

func (*Stmt) Reset

func (s *Stmt) Reset()

Reset resets the statement.

func (*Stmt) Step

func (s *Stmt) Step() (bool, error)

Step executes the statement and returns whether more rows are available.

type TableData

type TableData struct {
	Rows      [][]interface{}
	NextRowID int64
	ColNames  []string // Column names for the table
}

TableData holds in-memory table data

func (*TableData) AddRow

func (t *TableData) AddRow(row []interface{})

AddRow adds a row to the table

func (*TableData) GetNextRowID

func (t *TableData) GetNextRowID() int64

GetNextRowID returns the next row ID

func (*TableData) GetRows

func (t *TableData) GetRows() [][]interface{}

GetRows returns the rows in this table

func (*TableData) RemoveRow

func (t *TableData) RemoveRow(idx int)

RemoveRow removes a row at the given index

func (*TableData) SetNextRowID

func (t *TableData) SetNextRowID(id int64)

SetNextRowID sets the next row ID

Directories

Path Synopsis
Package btree implements the SQLite B-Tree storage engine.
Package btree implements the SQLite B-Tree storage engine.
Package codegen generates VDBE bytecode from AST.
Package codegen generates VDBE bytecode from AST.
Package expr provides expression evaluation for SQL.
Package expr provides expression evaluation for SQL.
Package func provides built-in SQL functions.
Package func provides built-in SQL functions.
Package pager implements the SQLite Pager layer for page management.
Package pager implements the SQLite Pager layer for page management.
Package parser provides SQL parsing and AST definitions.
Package parser provides SQL parsing and AST definitions.
Package schema provides the database schema and catalog management.
Package schema provides the database schema and catalog management.
Package tokenize provides SQL tokenization.
Package tokenize provides SQL tokenization.
Package transaction provides transaction and savepoint management.
Package transaction provides transaction and savepoint management.
Package vdbe provides the Virtual Database Engine for executing SQL.
Package vdbe provides the Virtual Database Engine for executing SQL.
Package vfs provides SQLite-compatible VFS (Virtual File System) implementations.
Package vfs provides SQLite-compatible VFS (Virtual File System) implementations.
Package wal implements the SQLite Write-Ahead Log (WAL).
Package wal implements the SQLite Write-Ahead Log (WAL).

Jump to

Keyboard shortcuts

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