query

package
v0.0.0-...-6596822 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 0 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SortedKeys

func SortedKeys(m map[string]any) []string

SortedKeys 返回 map 的排序键。

Types

type Aggregate

type Aggregate struct {
	Function string
	Columns  []any
}

type Expression

type Expression interface {
	GetValue() interface{}
}

Expression 表示原生 SQL 表达式片段(等价于 raw 表达式,值直接嵌入语句)。

type GroupLimit

type GroupLimit struct {
	Column string
	Value  int64
}

GroupLimit 表示 groupLimit(预加载分组限额)。

type IndexHint

type IndexHint struct {
	Type  string
	Index string
}

IndexHint 索引提示:type ∈ hint/force/ignore

type Join

type Join struct {
	// Type: inner / left / right / cross / straight_join
	Type string
	// Table: string 或 Expression(joinSub / joinLateral 场景)
	Table any
	// Lateral 标记 lateral join(joinLateral 子句)
	Lateral bool
	// 嵌套 join(JoinClause->joins)
	Joins  []*Join
	Wheres []*Where
}

type KV

type KV struct {
	Key   string
	Value any
}

KV 是有序键值对;Row 对应 PHP 有序数组的 Go 等价物(保持列序)。 map[string]any 在 Go 中无序,插入场景若依赖列序请使用 Row。

type Order

type Order struct {
	Column    any
	Direction string
	// orderByRaw:Expression 或 string
	Sql any
	// Type:InOrderOf(inOrderOf 顺序排序);空 = 普通列排序
	Type string
	// InOrderOf 的取值序列(Type == "InOrderOf" 时使用)
	Values []any
}

type Query

type Query struct {
	Aggregate *Aggregate

	// Columns: 元素为 string 或 Expression(含子查询 Expression)
	Columns []any

	// Distinct: bool 或 []any(Postgres distinct on)
	Distinct any

	// From: string 或 Expression
	From any

	IndexHint *IndexHint

	Joins []*Join

	Wheres []*Where

	// Groups: 元素为 string 或 Expression
	Groups []any

	// Havings 与 Where 同构(havings 即 where 数组)
	Havings []*Where

	Orders []*Order

	// Limit/Offset: nil 表示未设置(null)
	Limit  *int64
	Offset *int64

	Unions      []*Union
	UnionOrders []*Order
	UnionLimit  *int64
	UnionOffset *int64

	// Lock: nil / bool / string
	Lock any

	// CTE(with/withRecursive)
	Withes        []*With
	WithRecursive bool

	// GroupLimit:预加载分组 limit(compileGroupLimit)
	GroupLimit *GroupLimit

	// 标记当前 Query 是 join 子句(编译 on 而非 where)
	JoinClause bool

	// Timeout 查询执行超时(秒),MySQL 编译为 MAX_EXECUTION_TIME 提示。
	Timeout *int64
}

type RawExpression

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

RawExpression 是 Expression 的默认实现。

func NewExpression

func NewExpression(value interface{}) *RawExpression

func (*RawExpression) GetValue

func (e *RawExpression) GetValue() interface{}

type Row

type Row []KV

func ToRow

func ToRow(m map[string]any) Row

ToRow 把 map 转为按 key 排序的 Row(确定性顺序)。

func (Row) Columns

func (r Row) Columns() []string

Columns 返回行内列名(保序)。

func (Row) Value

func (r Row) Value(key string) (any, bool)

Value 取某列的值(不存在返回 nil, false)。

type Union

type Union struct {
	All   bool
	Query *Query
}

type Where

type Where struct {
	Type     string
	Column   any
	Operator string
	Value    any
	Values   []any
	// whereColumn 的两列比较 / whereRowValues 等
	First  any
	Second any
	// 括号分组字段(whereBetweenColumns / RowValues 的多列)
	Columns []any
	// Raw 的 SQL 片段(string 或 Expression)
	Sql any
	// 嵌套/子查询
	Query *Query
	// In/Null/Between/Nested 的 not 标记
	Not bool
	// whereLike 大小写敏感
	CaseSensitive bool
	// whereFullText 的选项(mode/expanded)
	Options map[string]any

	Boolean string
}

type With

type With struct {
	Name    string
	Columns []string
	Query   *Query
}

With 对应 CTE:with "name" (cols) as (sub)

Jump to

Keyboard shortcuts

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