api

package
v1.68.5 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSystemTableAccessDenied = fmt.Errorf("system table access denied: super_admin role required")

Functions

This section is empty.

Types

type AggFunc

type AggFunc string
const (
	AggNone  AggFunc = ""
	AggCount AggFunc = "COUNT"
	AggSum   AggFunc = "SUM"
	AggAvg   AggFunc = "AVG"
	AggMin   AggFunc = "MIN"
	AggMax   AggFunc = "MAX"
)

type AlterTableStmt

type AlterTableStmt struct {
	Table string
	Plan  kernal.AlterTablePlan
}

func (AlterTableStmt) TableName

func (s AlterTableStmt) TableName() string

func (AlterTableStmt) Type

func (s AlterTableStmt) Type() StatementType

type Backend

type Backend string
const (
	BackendDriver Backend = "driver"
	BackendKernal Backend = "kernal"
)

type CreateTableStmt

type CreateTableStmt struct {
	Table  string
	Schema kernal.TableSchema
}

func (CreateTableStmt) TableName

func (s CreateTableStmt) TableName() string

func (CreateTableStmt) Type

func (s CreateTableStmt) Type() StatementType

type DeleteStmt

type DeleteStmt struct {
	Table      string
	Conditions []kernal.QueryCondition
}

func (DeleteStmt) TableName

func (s DeleteStmt) TableName() string

func (DeleteStmt) Type

func (s DeleteStmt) Type() StatementType

type DropTableStmt

type DropTableStmt struct{ Table string }

func (DropTableStmt) TableName

func (s DropTableStmt) TableName() string

func (DropTableStmt) Type

func (s DropTableStmt) Type() StatementType

type Engine

type Engine struct {
	Database string
	Backend  Backend
	Actor    *driver.AuthenticatedUser
	// contains filtered or unexported fields
}

func NewEngine

func NewEngine(database string, backend Backend) *Engine

func (*Engine) Close

func (e *Engine) Close() error

func (*Engine) Execute

func (e *Engine) Execute(sql string) (ExecResult, error)

func (*Engine) ExecuteStatement

func (e *Engine) ExecuteStatement(stmt Statement) (ExecResult, error)

func (*Engine) Parse

func (e *Engine) Parse(sql string) (Statement, error)

func (*Engine) WithActor

func (e *Engine) WithActor(user *driver.AuthenticatedUser) *Engine

func (*Engine) WithDBAttrs

func (e *Engine) WithDBAttrs(attrs ...kernal.SchemaAttributer) *Engine

func (*Engine) WithSharedCacheFrom

func (e *Engine) WithSharedCacheFrom(other *Engine) *Engine

type ExecResult

type ExecResult struct {
	Rows         []kernal.Row  `json:"rows,omitempty"`
	Affected     int           `json:"affected"`
	Inserted     kernal.Row    `json:"inserted,omitempty"`
	InsertedRows []kernal.Row  `json:"insertedRows,omitempty"`
	Updated      kernal.Row    `json:"updated,omitempty"`
	UpdatedRows  []kernal.Row  `json:"updatedRows,omitempty"`
	Statement    StatementType `json:"statement"`
}

type InsertStmt

type InsertStmt struct {
	Table string
	Row   kernal.Row
	Rows  []kernal.Row
}

func (InsertStmt) TableName

func (s InsertStmt) TableName() string

func (InsertStmt) Type

func (s InsertStmt) Type() StatementType

type JoinClause

type JoinClause struct {
	Type       JoinType // INNER | LEFT
	Table      string   // 从表名
	LeftAlias  string   // 主表字段(可含 "alias.field")
	RightAlias string   // 从表字段(可含 "alias.field")
}

type JoinType

type JoinType string
const (
	JoinInner JoinType = "INNER"
	JoinLeft  JoinType = "LEFT"
)

type SelectField

type SelectField struct {
	Star     bool    // SELECT *
	Field    string  // plain column name
	Agg      AggFunc // COUNT / SUM / AVG / MIN / MAX
	AggField string  // field inside aggregate ("*" for COUNT(*))
	Alias    string  // AS alias
}

type SelectStmt

type SelectStmt struct {
	Table      string
	Fields     []SelectField
	Joins      []JoinClause
	Conditions []kernal.QueryCondition
	SubConds   []SubqueryCondition
	GroupBy    []string
	OrderBy    string
	OrderDesc  bool
	Limit      int
	Offset     int
}

func (SelectStmt) TableName

func (s SelectStmt) TableName() string

func (SelectStmt) Type

func (s SelectStmt) Type() StatementType

type Statement

type Statement interface {
	Type() StatementType
	TableName() string
}

func Parse

func Parse(sql string) (Statement, error)

type StatementType

type StatementType string
const (
	StmtCreateTable StatementType = "create_table"
	StmtAlterTable  StatementType = "alter_table"
	StmtInsert      StatementType = "insert"
	StmtUpdate      StatementType = "update"
	StmtDelete      StatementType = "delete"
	StmtSelect      StatementType = "select"
	StmtDropTable   StatementType = "drop_table"
	StmtTruncate    StatementType = "truncate_table"
)

type SubqueryCondition

type SubqueryCondition struct {
	Field   string
	NotIn   bool
	SubStmt SelectStmt
}

SubqueryCondition 表示 IN/NOT IN 子查询条件,由 engine 展开为具体值列表后传入 kernal

type TruncateTableStmt

type TruncateTableStmt struct{ Table string }

func (TruncateTableStmt) TableName

func (s TruncateTableStmt) TableName() string

func (TruncateTableStmt) Type

type UpdateStmt

type UpdateStmt struct {
	Table       string
	PrimaryKey  any
	PrimaryKeys []any
	Updates     kernal.Row
}

func (UpdateStmt) TableName

func (s UpdateStmt) TableName() string

func (UpdateStmt) Type

func (s UpdateStmt) Type() StatementType

Jump to

Keyboard shortcuts

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