Documentation ¶
Index ¶
- Constants
- Variables
- func BoolFormatter(data string) interface{}
- func Compose(fns ...func(data string) error) func(data string) error
- func IntegerFormatter(data string) interface{}
- func IsBool(data string) error
- func IsInteger(data string) error
- func IsSignedInteger(data string) error
- func IsString(data string) error
- func NotEmpty(data string) error
- func OptionLimit[T int | string](data T, options []T) error
- func StringFormatter(data string) interface{}
- func TrimQuotes(data string) string
- func VarcharTooLong(data string, maxLen int) error
- type BPItem
- type BPNode
- type BPTree
- type ConstraintError
- type CreateTableAST
- type DB
- func (db *DB) AddTable(table *Table)
- func (db *DB) CreateTable(parser *Parser, sql string) error
- func (db *DB) Delete(parser *Parser, sql string) error
- func (db *DB) Exec(sql string) error
- func (db *DB) GetTable(tableName string) *Table
- func (db *DB) Insert(parser *Parser, sql string) error
- func (db *DB) NewTable(ast *CreateTableAST) (*Table, error)
- func (db *DB) Query(sql string) ([]*BPItem, error)
- func (db *DB) Update(parser *Parser, sql string) error
- type DeleteAST
- type InsertAST
- type Parser
- func (p *Parser) GetSQLType(sql string) StatementType
- func (p *Parser) ParseCreateTable(sql string) (ast *CreateTableAST, err error)
- func (p *Parser) ParseDelete(sql string) (ast *DeleteAST, err error)
- func (p *Parser) ParseInsert(insert string) (ast *InsertAST, err error)
- func (p *Parser) ParseSelect(sql string) (ast *SelectAST, err error)
- func (p *Parser) ParseUpdate(sql string) (ast *UpdateAST, err error)
- func (p *Parser) ScanSet(s *scanner.Scanner) ([]string, []string, string, error)
- func (p *Parser) ScanTable(s *scanner.Scanner) (PrimaryKey string, Columns []string, Type []string, NotNull []bool, ...)
- func (p *Parser) ScanWhere(s *scanner.Scanner) ([]string, string, error)
- func (p *Parser) ScanWhereAndLimit(s *scanner.Scanner, lastToken string) (where []string, limit int64, err error)
- type Plan
- type SelectAST
- type StatementType
- type Table
- func (t *Table) CheckDeleteConstraint(ast *DeleteAST) *ConstraintError
- func (t *Table) CheckInsertConstraint(ast *InsertAST) *ConstraintError
- func (t *Table) CheckLimit(limit int64) *ConstraintError
- func (t *Table) CheckSelectConstraint(ast *SelectAST) *ConstraintError
- func (t *Table) CheckTable(table string) *ConstraintError
- func (t *Table) CheckUpdateConstraint(ast *UpdateAST) *ConstraintError
- func (t *Table) CheckWhere(where []string) *ConstraintError
- func (t *Table) FilterCols(item *BPItem, cols []string) *BPItem
- func (t *Table) Format(ast *InsertAST) map[int64][]interface{}
- func (t *Table) GetClusterIndex() *BPTree
- type UpdateAST
Constants ¶
View Source
const ( UNSUPPORTED = "N/A" SELECT = "SELECT" INSERT = "INSERT" UPDATE = "UPDATE" DELETE = "DELETE" CREATE = "CREATE" TABLE = "TABLE" FROM = "FROM" WHERE = "WHERE" LIMIT = "LIMIT" INTO = "INTO" VALUES = "VALUES" Set = "SET" ASTERISK = "*" NULL = "NULL" DEFAULT = "DEFAULT" PRIMARY = "PRIMARY" KEY = "KEY" NOT = "not" AND = "and" OR = "or" )
SQL type tokens
Variables ¶
View Source
var ( IsNotInteger = fmt.Errorf("is not inetger") IsSignedIntegerError = fmt.Errorf("is not signed integer") IsNotString = fmt.Errorf("is not string") IsNotBoolError = fmt.Errorf("is not bool") HasNoPrimaryKeyError = fmt.Errorf("has no primary key") NotEmptyError = fmt.Errorf("not empty") VarCharTooLongError = fmt.Errorf("varchar too long") OptionLimitError = fmt.Errorf("option limit error") DuplicateKeyError = fmt.Errorf("duplicate key") HasNotColumnError = fmt.Errorf("has no such column") TableError = fmt.Errorf("has no such table") SyntaxError = fmt.Errorf("syntax error") )
Functions ¶
func BoolFormatter ¶
func BoolFormatter(data string) interface{}
func IntegerFormatter ¶
func IntegerFormatter(data string) interface{}
func IsSignedInteger ¶
func OptionLimit ¶
func StringFormatter ¶
func StringFormatter(data string) interface{}
func TrimQuotes ¶
func VarcharTooLong ¶
Types ¶
type BPNode ¶
type BPTree ¶
type BPTree struct {
// contains filtered or unexported fields
}
func (*BPTree) GetAllItems ¶
func (*BPTree) GetFarLeftLeaf ¶
type ConstraintError ¶
type CreateTableAST ¶
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
func (*Parser) GetSQLType ¶
func (p *Parser) GetSQLType(sql string) StatementType
func (*Parser) ParseCreateTable ¶
func (p *Parser) ParseCreateTable(sql string) (ast *CreateTableAST, err error)
func (*Parser) ParseInsert ¶
ParseInsert can parse a simple INSERT statement, eg.
INSERT INTO table_name VALUES (value1, value2, …) or INSERT INTO table_name(column1, column2, …) VALUES (value1, value2, …)
func (*Parser) ParseSelect ¶
ParseSelect is a simple select statement parser. It's just a demo of SELECT statement parser skeleton. Currently, the most complex SQL supported here is something like:
SELECT * FROM foo WHERE id < 3 LIMIT 1;
Even SQL-92 standard is far more complex. For a production ready SQL parser, see: https://github.com/auxten/postgresql-parser
type Plan ¶
type StatementType ¶
type StatementType string
type Table ¶
type Table struct { Name string PrimaryKey string Columns []string Constraint map[string]func(data string) error Formatter map[string]func(data string) interface{} DefaultValue []interface{} Indies map[string]*BPTree // multi indies, maybe }
Table get table from .frm file
func (*Table) CheckDeleteConstraint ¶
func (t *Table) CheckDeleteConstraint(ast *DeleteAST) *ConstraintError
func (*Table) CheckInsertConstraint ¶
func (t *Table) CheckInsertConstraint(ast *InsertAST) *ConstraintError
func (*Table) CheckLimit ¶
func (t *Table) CheckLimit(limit int64) *ConstraintError
func (*Table) CheckSelectConstraint ¶
func (t *Table) CheckSelectConstraint(ast *SelectAST) *ConstraintError
func (*Table) CheckTable ¶
func (t *Table) CheckTable(table string) *ConstraintError
func (*Table) CheckUpdateConstraint ¶
func (t *Table) CheckUpdateConstraint(ast *UpdateAST) *ConstraintError
func (*Table) CheckWhere ¶
func (t *Table) CheckWhere(where []string) *ConstraintError
func (*Table) GetClusterIndex ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.