executor

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Overview

Package executor provides SQL query execution for XxSql.

Package executor provides SQL query execution for XxSql.

Index

Constants

View Source
const (
	SysTableMicroservices = "_sys_ms"
	SysTableProjects      = "_sys_projects"
	SysTablePlugins       = "_sys_plugins"
)

System table names

Variables

This section is empty.

Functions

func InitSystemMicroservices added in v0.0.7

func InitSystemMicroservices(engine *storage.Engine, dataDir string) error

InitSystemMicroservices inserts preset system microservice scripts

func InitSystemTables added in v0.0.7

func InitSystemTables(engine *storage.Engine) error

InitSystemTables initializes system tables for XxSql. This should be called when the server first starts.

func InsertSystemMicroservice added in v0.0.7

func InsertSystemMicroservice(engine *storage.Engine, skey, script, description string) error

InsertSystemMicroservice inserts a microservice script into _sys_ms table

func NewAnalyzeTable added in v0.0.5

func NewAnalyzeTable() *optimizer.AnalyzeTable

NewAnalyzeTable creates a new table analyzer. This is a helper that wraps the optimizer's AnalyzeTable.

func NewOptimizer added in v0.0.5

func NewOptimizer() *optimizer.Optimizer

NewOptimizer creates a new query optimizer.

Types

type AuthManager

type AuthManager interface {
	CreateUser(username, password string, role int) (interface{}, error)
	DeleteUser(username string) error
	GetUser(username string) (interface{}, error)
	ChangePassword(username, oldPassword, newPassword string) error
	GrantGlobal(username string, priv interface{}) error
	GrantDatabase(username, database string, priv interface{}) error
	GrantTable(username, database, table string, priv interface{}) error
	RevokeGlobal(username string, priv interface{}) error
	RevokeDatabase(username, database string, priv interface{}) error
	RevokeTable(username, database, table string, priv interface{}) error
	GetGrants(username string) ([]string, error)
}

AuthManager interface for auth operations.

type BackupManagerWrapper

type BackupManagerWrapper struct {
	*backup.Manager
}

BackupManagerWrapper wraps the backup.Manager for use with storage.Engine.

func NewBackupManager

func NewBackupManager(engine *storage.Engine) *BackupManagerWrapper

NewBackupManager creates a backup manager for the storage engine.

type ColumnInfo

type ColumnInfo struct {
	Name  string
	Type  string
	Alias string // optional alias for ORDER BY support
}

ColumnInfo represents column information for results.

type DatabasePrivilege

type DatabasePrivilege struct {
	Select bool
	Insert bool
	Update bool
	Delete bool
	Create bool
	Drop   bool
	Index  bool
}

DatabasePrivilege represents database privileges for executor.

type Executor

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

Executor executes SQL queries against the storage engine.

func NewExecutor

func NewExecutor(engine *storage.Engine) *Executor

NewExecutor creates a new executor.

func (*Executor) Engine

func (e *Executor) Engine() *storage.Engine

Engine returns the storage engine (for testing).

func (*Executor) Execute

func (e *Executor) Execute(sqlStr string) (*Result, error)

Execute executes a SQL statement.

func (*Executor) ExecuteForScript added in v0.0.6

func (e *Executor) ExecuteForScript(sqlStr string) (interface{}, error)

ExecuteForScript executes a SQL statement and returns the result as interface{}. This method satisfies the xxscript.SQLExecutor interface.

func (*Executor) ExecuteWithPerms

func (e *Executor) ExecuteWithPerms(sqlStr string, checker PermissionChecker) (*Result, error)

ExecuteWithPerms executes a SQL statement with a specific permission checker.

func (*Executor) GetFTSManager added in v0.0.5

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

GetFTSManager returns the FTS manager for external use.

func (*Executor) GetPragmaValue added in v0.0.5

func (e *Executor) GetPragmaValue(name string) interface{}

GetPragmaValue returns the current value of a pragma (for internal use).

func (*Executor) InTransaction added in v0.0.5

func (e *Executor) InTransaction() bool

InTransaction returns true if a transaction is currently in progress.

func (*Executor) SetAuthManager

func (e *Executor) SetAuthManager(mgr AuthManager)

SetAuthManager sets the auth manager.

func (*Executor) SetDatabase

func (e *Executor) SetDatabase(db string)

SetDatabase sets the current database.

func (*Executor) SetPermissionChecker

func (e *Executor) SetPermissionChecker(checker PermissionChecker)

SetPermissionChecker sets the permission checker.

func (*Executor) SetScriptUDFManager added in v0.0.6

func (e *Executor) SetScriptUDFManager(m *ScriptUDFManager)

SetScriptUDFManager sets the script-based UDF manager for the executor.

func (*Executor) SetUDFManager added in v0.0.5

func (e *Executor) SetUDFManager(m *UDFManager)

SetUDFManager sets the UDF manager for the executor.

type GlobalPrivilege

type GlobalPrivilege struct {
	Select bool
	Insert bool
	Update bool
	Delete bool
	Create bool
	Drop   bool
	Index  bool
	Grant  bool
}

GlobalPrivilege represents global privileges for executor.

type IndexCondition added in v0.0.5

type IndexCondition struct {
	ColumnName string
	Op         sql.BinaryOp
	Value      interface{}
	IsRange    bool // true for <, <=, >, >=
	IsEquality bool // true for =
}

IndexCondition represents a condition that can use an index.

type Permission

type Permission uint32

Permission represents a permission bit.

const (
	PermManageUsers Permission = 1 << iota
	PermManageConfig
	PermStartStop
	PermCreateTable
	PermDropTable
	PermCreateDatabase
	PermDropDatabase
	PermSelect
	PermInsert
	PermUpdate
	PermDelete
	PermCreateIndex
	PermDropIndex
	PermBackup
	PermRestore
)

type PermissionChecker

type PermissionChecker interface {
	HasPermission(perm Permission) bool
}

PermissionChecker checks if a permission is granted.

type Result

type Result struct {
	Columns    []ColumnInfo
	Rows       [][]interface{}
	RowCount   int
	Affected   int
	LastInsert uint64
	Message    string
}

Result represents the result of a query execution.

type ScriptFunction added in v0.0.6

type ScriptFunction struct {
	Name       string   `json:"name"`
	Params     []string `json:"params"`
	ReturnType string   `json:"return_type"`
	Script     string   `json:"script"`
}

ScriptFunction represents a user-defined function implemented in XxScript.

type ScriptUDFManager added in v0.0.6

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

ScriptUDFManager manages user-defined functions implemented in XxScript. Note: The actual script execution is done in the Executor to avoid import cycles.

func NewScriptUDFManager added in v0.0.6

func NewScriptUDFManager(dataDir string) *ScriptUDFManager

NewScriptUDFManager creates a new script-based UDF manager.

func (*ScriptUDFManager) CreateFunction added in v0.0.6

func (m *ScriptUDFManager) CreateFunction(fn *ScriptFunction, replace bool) error

CreateFunction creates a new script-based function.

func (*ScriptUDFManager) DropFunction added in v0.0.6

func (m *ScriptUDFManager) DropFunction(name string) error

DropFunction drops a user-defined function.

func (*ScriptUDFManager) Exists added in v0.0.6

func (m *ScriptUDFManager) Exists(name string) bool

Exists checks if a function exists.

func (*ScriptUDFManager) GetFunction added in v0.0.6

func (m *ScriptUDFManager) GetFunction(name string) (*ScriptFunction, bool)

GetFunction retrieves a function by name.

func (*ScriptUDFManager) ListFunctions added in v0.0.6

func (m *ScriptUDFManager) ListFunctions() []string

ListFunctions returns all function names.

func (*ScriptUDFManager) Load added in v0.0.6

func (m *ScriptUDFManager) Load() error

Load loads functions from disk.

func (*ScriptUDFManager) Save added in v0.0.6

func (m *ScriptUDFManager) Save() error

Save saves all functions to disk.

type SessionPermissionAdapter

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

SessionPermissionAdapter adapts auth session permissions to executor permissions.

func NewSessionPermissionAdapter

func NewSessionPermissionAdapter(hasPermFunc func(perm uint32) bool) *SessionPermissionAdapter

NewSessionPermissionAdapter creates a new adapter from a session's HasPermission function.

func (*SessionPermissionAdapter) HasPermission

func (a *SessionPermissionAdapter) HasPermission(perm Permission) bool

HasPermission implements PermissionChecker.

type TablePrivilege

type TablePrivilege struct {
	Select bool
	Insert bool
	Update bool
	Delete bool
	Create bool
	Drop   bool
	Index  bool
}

TablePrivilege represents table privileges for executor.

type UDFManager added in v0.0.5

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

UDFManager manages user-defined functions.

func NewUDFManager added in v0.0.5

func NewUDFManager(dataDir string) *UDFManager

NewUDFManager creates a new UDF manager.

func (*UDFManager) CreateFunction added in v0.0.5

func (m *UDFManager) CreateFunction(fn *sql.UserFunction, replace bool) error

CreateFunction creates a new user-defined function.

func (*UDFManager) DropFunction added in v0.0.5

func (m *UDFManager) DropFunction(name string) error

DropFunction drops a user-defined function.

func (*UDFManager) Exists added in v0.0.5

func (m *UDFManager) Exists(name string) bool

Exists checks if a function exists.

func (*UDFManager) GetFunction added in v0.0.5

func (m *UDFManager) GetFunction(name string) (*sql.UserFunction, bool)

GetFunction retrieves a user-defined function by name.

func (*UDFManager) ListFunctions added in v0.0.5

func (m *UDFManager) ListFunctions() []string

ListFunctions returns all user-defined function names.

func (*UDFManager) Load added in v0.0.5

func (m *UDFManager) Load() error

Load loads functions from disk.

func (*UDFManager) Save added in v0.0.5

func (m *UDFManager) Save() error

Save saves all functions to disk.

type UpdatableViewInfo added in v0.0.5

type UpdatableViewInfo struct {
	BaseTableName  string
	BaseTableCols  []string // Column names in the base table
	ViewColumns    []string // Column names in the view (mapped to base)
	WhereClause    sql.Expression
	CheckOption    string             // "CASCADED", "LOCAL", or ""
	UnderlyingView *UpdatableViewInfo // For nested views
}

UpdatableViewInfo contains information about an updatable view.

Jump to

Keyboard shortcuts

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