db

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package db provides the SQL execution engine for CommitDB.

The Engine type is the main entry point for executing SQL statements. It parses SQL, executes queries, and returns results.

Engine Usage

engine := db.NewEngine(persistence, identity)
result, err := engine.Execute("SELECT * FROM mydb.users")
if err != nil {
    log.Fatal(err)
}
result.Display()

Result Types

There are two result types:

  • QueryResult: Returned by SELECT statements
  • CommitResult: Returned by INSERT, UPDATE, DELETE, CREATE, DROP

QueryResult contains columns, data rows, and execution metrics. CommitResult contains counts of affected objects and the transaction ID.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommitResult

type CommitResult struct {
	Transaction      ps.Transaction
	DatabasesCreated int
	DatabasesDeleted int
	TablesCreated    int
	TablesDeleted    int
	TablesAltered    int
	RecordsWritten   int
	RecordsDeleted   int
	ExecutionTimeSec float64
	ExecutionOps     int
}

func (CommitResult) Display

func (result CommitResult) Display()

func (CommitResult) ExecutionTime

func (result CommitResult) ExecutionTime() string

func (CommitResult) Type

func (result CommitResult) Type() ResultType

type Engine

type Engine struct {
	*ps.Persistence
	QueryContext
}

func NewEngine

func NewEngine(persistence *ps.Persistence, identity core.Identity) *Engine

func (*Engine) Execute

func (engine *Engine) Execute(query string) (Result, error)

type QueryContext

type QueryContext struct {
	Identity core.Identity
}

type QueryResult

type QueryResult struct {
	Transaction      ps.Transaction
	Columns          []string
	Data             [][]string
	RecordsRead      int
	ExecutionTimeSec float64
	ExecutionOps     int
}

func (QueryResult) Display

func (result QueryResult) Display()

func (QueryResult) ExecutionTime

func (result QueryResult) ExecutionTime() string

func (QueryResult) Type

func (result QueryResult) Type() ResultType

type Result

type Result interface {
	Type() ResultType
	Display()
}

type ResultType

type ResultType int
const (
	QueryResultType ResultType = iota
	CommitResultType
)

type SimpleTable

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

SimpleTable provides basic table formatting without external dependencies

func NewTable

func NewTable(w io.Writer) *SimpleTable

NewTable creates a new table writer

func (*SimpleTable) Bulk

func (t *SimpleTable) Bulk(rows [][]string)

Bulk adds multiple rows

func (*SimpleTable) Header

func (t *SimpleTable) Header(headers []string)

Header sets the table headers

func (*SimpleTable) Render

func (t *SimpleTable) Render()

Render outputs the formatted table

func (*SimpleTable) Row

func (t *SimpleTable) Row(row []string)

Row adds a single row

Jump to

Keyboard shortcuts

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