memdb

package
v0.0.0-...-098ca1c Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

* @Author: wangjun haodreams@163.com * @Date: 2024-05-09 13:27:28 * @LastEditors: wangjun haodreams@163.com * @LastEditTime: 2024-05-17 08:59:56 * @FilePath: \golib\memdb\ast_sql.go * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewParser

func NewParser() *participle.Parser[SelectStmt]

func Where

func Where(t *memtable.Table, cond *Condition) (table *memtable.Table, err error)

where 查询

Types

type Array

type Array struct {
	StrArray []string  `parser:"@String ( ',' @String )* "`
	NumArray []float64 `parser:"| @Number ( ',' @Number )* "`
}

type Compare

type Compare struct {
	Operator string   `parser:"@( '<>' | '<=' | '>=' | '=' | '<' | '>' | '!=' )"`
	String   *string  `parser:"(@String"`
	Math     *Math    ` parser:" | @@"` //数学表达式
	Number   *float64 `parser:" | @Number)"`
}

type CondRHS

type CondRHS struct {
	Compare *Compare ` parser:" @@"`
	Is      *Is      `parser:"| 'IS' @@"`
	In      *Array   `parser:"| 'IN' '(' @@ ')'"`
	Like    *Like    `parser:"| 'LIKE' @@"`
}

type Condition

type Condition struct {
	Name    string   `parser:"@Ident"`
	CondRHS *CondRHS `parser:"@@?"`
}

type Database

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

表的where支持逻辑和数学一维函数, 例如 where a < b * 100,,数学常量放在表达式最后面 表的字段暂不支持数学函数 例如 select a * 100

func NewDatabase

func NewDatabase() *Database

func (*Database) GetTable

func (m *Database) GetTable(name string) *memtable.Table

获取表

func (*Database) Query

func (m *Database) Query(sql string) (tempTable *memtable.TempTable, err error)

根据sql查询数据,返回临时表

func (*Database) RegisterMemTable

func (m *Database) RegisterMemTable(table *memtable.Table, name string) (err error)

func (*Database) RegisterTable

func (m *Database) RegisterTable(table any, key string, names ...string) (err error)

func (*Database) Tables

func (m *Database) Tables() []*memtable.Table

type Field

type Field struct {
	Name []string `parser:"@Ident ('(' @Ident ')')*"`
	//Name1 string `|`
	As string `parser:"( 'AS' @Ident )?"`
}

type Fields

type Fields struct {
	Field []*Field `parser:"@@ ( ',' @@ )*"`
}

type FillBy

type FillBy struct {
	Name []string  `parser:"@Ident ( ',' @Ident )*"`
	Vals []float64 `parser:"'(' @Number ( ',' @Number )* ')'"`
}

type GroupBy

type GroupBy struct {
	Name []string `parser:"@Ident ( ',' @Ident )*"`
}

@Ident a-z A-Z 0-9 _ * 任意字符

type Is

type Is struct {
	Not  bool `parser:"[ @'NOT' ]"`
	Null bool ` parser:"@'NULL'"`
}

type Like

type Like struct {
	Not     bool   `parser:"[ @'NOT' ]"`
	Operand string `parser:"@String"`
}

type Math

type Math struct {
	Name     string  `parser:"@Ident"`
	Operator string  `parser:"@( '+' | '-' | '*' | '/' | '%' )"`
	Number   float64 `parser:"@Number"`
}

数学函数

type NumCompare

type NumCompare func(x, y float64) bool

type NumMath

type NumMath func(x, y float64) float64

type OrderBy

type OrderBy struct {
	Name string `parser:"@Ident"`
	DESC bool   `parser:"[ @'DESC' ]"`
}

type SelectStmt

type SelectStmt struct {
	Select  string       `parser:"@('SELECT') "`
	Fields  []*Field     `parser:"@@ ( ',' @@ )*"`
	From    string       `parser:"'FROM' @Ident"`
	Where   []*Condition `parser:"( 'WHERE' @@  ( 'AND' @@ )*)?"`
	GroupBy *GroupBy     `parser:"('GROUP' 'BY' (@@)*)?"`
	FillBy  *FillBy      `parser:"('FILL' 'BY' (@@)*)?"`
	OrderBy *OrderBy     `parser:"('ORDER' 'BY' (@@)*)?"`
}

SelectStmt based on http://www.h2database.com/html/grammar.html

type StatisFunc

type StatisFunc func(table *memtable.Table, idx int) float64 //统计函数

type StrCompare

type StrCompare func(x, y string) bool

Jump to

Keyboard shortcuts

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