ast

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package ast (Abstract Syntax Tree) is a tree representation of the abstract synthetic structure of go4sql.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Anonymitifier added in v0.0.2

type Anonymitifier struct {
	Token token.Token // the token.IDENT token
}

Anonymitifier - Represent Token with string value that is equal to simple value that is put into columns

func (Anonymitifier) GetToken added in v0.0.2

func (ls Anonymitifier) GetToken() token.Token

func (Anonymitifier) IsIdentifier added in v0.0.2

func (ls Anonymitifier) IsIdentifier() bool

type BooleanExpression added in v0.0.2

type BooleanExpression struct {
	Boolean token.Token // example: token.TRUE
}

BooleanExpression - TokenType of Expression that represent single boolean value

Example: TRUE

func (BooleanExpression) GetIdentifiers added in v0.0.2

func (ls BooleanExpression) GetIdentifiers() []Identifier

type Command

type Command interface {
	Node
	CommandNode()
}

Command - Part of sequence - represent single static command

Example: SELECT * FROM Customers;

type ConditionExpression added in v0.0.2

type ConditionExpression struct {
	Left      Tifier      // name of column
	Right     Tifier      // value which column should have
	Condition token.Token // example: token.EQUAL
}

ConditionExpression - TokenType of Expression that represent condition that is comparing value from column to static one

Example: column1 EQUAL 123

func (ConditionExpression) GetIdentifiers added in v0.0.2

func (ls ConditionExpression) GetIdentifiers() []Identifier

type ContainExpression added in v1.0.0

type ContainExpression struct {
	Left     Identifier      // name of column
	Right    []Anonymitifier // name of column
	Contains bool            // IN or NOTIN
}

ContainExpression - TokenType of Expression that represents structure for IN operator

Example: colName IN ('value1', 'value2', 'value3')

func (ContainExpression) GetIdentifiers added in v1.0.0

func (ls ContainExpression) GetIdentifiers() []Identifier

type CreateCommand

type CreateCommand struct {
	Token       token.Token
	Name        Identifier // name of the table
	ColumnNames []string
	ColumnTypes []token.Token
}

CreateCommand - Part of Command that represent creation of table

Example: CREATE TABLE table1( one TEXT , two INT);

func (CreateCommand) CommandNode

func (ls CreateCommand) CommandNode()

func (CreateCommand) TokenLiteral

func (ls CreateCommand) TokenLiteral() string

type DeleteCommand added in v0.0.2

type DeleteCommand struct {
	Token        token.Token
	Name         Identifier    // name of the table
	WhereCommand *WhereCommand // optional
}

DeleteCommand - Part of Command that represent deleting row from table

Example: DELETE FROM tb1 WHERE two EQUAL 3;

func (DeleteCommand) CommandNode added in v0.0.2

func (ls DeleteCommand) CommandNode()

func (DeleteCommand) HasWhereCommand added in v1.0.0

func (ls DeleteCommand) HasWhereCommand() bool

HasWhereCommand - returns true if optional HasWhereCommand is present in SelectCommand

Example: SELECT * FROM table WHERE column1 NOT 'hi'; Returns true

SELECT * FROM table; Returns false

func (DeleteCommand) TokenLiteral added in v0.0.2

func (ls DeleteCommand) TokenLiteral() string

type DropCommand added in v1.0.0

type DropCommand struct {
	Token token.Token
	Name  Identifier // name of the table
}

DropCommand - Part of Command that represent dropping table

Example: DROP TABLE table;

func (DropCommand) CommandNode added in v1.0.0

func (ls DropCommand) CommandNode()

func (DropCommand) TokenLiteral added in v1.0.0

func (ls DropCommand) TokenLiteral() string

type Expression

type Expression interface {
	GetIdentifiers() []Identifier
}

Expression - Mathematical expression that is used to evaluate conditions

Methods:

GetIdentifiers - Return array for all Identifiers within expression

type Identifier

type Identifier struct {
	Token token.Token // the token.IDENT token
}

Identifier - Represent Token with string value that is equal to either column or table name

func (Identifier) GetToken added in v0.0.2

func (ls Identifier) GetToken() token.Token

func (Identifier) IsIdentifier added in v0.0.2

func (ls Identifier) IsIdentifier() bool

type InsertCommand

type InsertCommand struct {
	Token  token.Token
	Name   Identifier // name of the table
	Values []token.Token
}

InsertCommand - Part of Command that represent insertion of values into columns

Example: INSERT INTO table1 VALUES('hello', 1);

func (InsertCommand) CommandNode

func (ls InsertCommand) CommandNode()

func (InsertCommand) TokenLiteral

func (ls InsertCommand) TokenLiteral() string

type JoinCommand added in v1.0.0

type JoinCommand struct {
	Token      token.Token
	Name       Identifier // ex. name of table
	JoinType   token.Token
	Expression Expression
}

JoinCommand - Part of Command that represent JOIN statement with expression that will merge tables

Example: JOIN tbl2 ON tbl1.id EQUAL tbl2.f_idy;

func (JoinCommand) CommandNode added in v1.0.0

func (ls JoinCommand) CommandNode()

func (JoinCommand) ShouldTakeLeftSide added in v1.0.0

func (ls JoinCommand) ShouldTakeLeftSide() bool

func (JoinCommand) ShouldTakeRightSide added in v1.0.0

func (ls JoinCommand) ShouldTakeRightSide() bool

func (JoinCommand) TokenLiteral added in v1.0.0

func (ls JoinCommand) TokenLiteral() string

type LimitCommand added in v1.0.0

type LimitCommand struct {
	Token token.Token
	Count int
}

LimitCommand - Part of Command that limits results from SelectCommand

func (LimitCommand) CommandNode added in v1.0.0

func (ls LimitCommand) CommandNode()

func (LimitCommand) TokenLiteral added in v1.0.0

func (ls LimitCommand) TokenLiteral() string

type Node

type Node interface {
	TokenLiteral() string
}

Node is connector between commands and expressions

type OffsetCommand added in v1.0.0

type OffsetCommand struct {
	Token token.Token
	Count int
}

OffsetCommand - Part of Command that skip begging rows from SelectCommand

func (OffsetCommand) CommandNode added in v1.0.0

func (ls OffsetCommand) CommandNode()

func (OffsetCommand) TokenLiteral added in v1.0.0

func (ls OffsetCommand) TokenLiteral() string

type OperationExpression added in v0.0.2

type OperationExpression struct {
	Left      Expression  // another operation, condition or boolean
	Right     Expression  // another operation, condition or boolean
	Operation token.Token // example: token.AND
}

OperationExpression - TokenType of Expression that represent 2 other Expressions and conditional operation

Example: TRUE OR FALSE

func (OperationExpression) GetIdentifiers added in v0.0.2

func (ls OperationExpression) GetIdentifiers() []Identifier

type OrderByCommand added in v0.0.2

type OrderByCommand struct {
	Token        token.Token
	SortPatterns []SortPattern // column name and sorting type
}

OrderByCommand - Part of Command that ordering columns from SelectCommand

Example: ORDER BY column1 ASC, column2 DESC;

func (OrderByCommand) CommandNode added in v0.0.2

func (ls OrderByCommand) CommandNode()

func (OrderByCommand) TokenLiteral added in v0.0.2

func (ls OrderByCommand) TokenLiteral() string

type SelectCommand

type SelectCommand struct {
	Token          token.Token
	Name           Identifier      // ex. name of table
	Space          []Space         // ex. column names
	HasDistinct    bool            // DISTINCT keyword has been used
	WhereCommand   *WhereCommand   // optional
	OrderByCommand *OrderByCommand // optional
	LimitCommand   *LimitCommand   // optional
	OffsetCommand  *OffsetCommand  // optional
	JoinCommand    *JoinCommand    // optional
}

SelectCommand - Part of Command that represent selecting values from tables

Example: SELECT one, two FROM table1;

func (*SelectCommand) AggregateFunctionAppears added in v1.0.0

func (ls *SelectCommand) AggregateFunctionAppears() bool

func (SelectCommand) CommandNode

func (ls SelectCommand) CommandNode()

func (SelectCommand) HasJoinCommand added in v1.0.0

func (ls SelectCommand) HasJoinCommand() bool

HasJoinCommand - returns true if optional JoinCommand is present in SelectCommand

Example: SELECT * FROM table JOIN table2 ON table.one EQUAL table2.two; Returns true

SELECT * FROM table; Returns false

func (SelectCommand) HasLimitCommand added in v1.0.0

func (ls SelectCommand) HasLimitCommand() bool

HasLimitCommand - returns true if optional LimitCommand is present in SelectCommand

Example: SELECT * FROM table LIMIT 5; Returns true

SELECT * FROM table; Returns false

func (SelectCommand) HasOffsetCommand added in v1.0.0

func (ls SelectCommand) HasOffsetCommand() bool

HasOffsetCommand - returns true if optional OffsetCommand is present in SelectCommand

Example: SELECT * FROM table OFFSET 100; Returns true

SELECT * FROM table LIMIT 10; Returns false

func (SelectCommand) HasOrderByCommand added in v1.0.0

func (ls SelectCommand) HasOrderByCommand() bool

HasOrderByCommand - returns true if optional OrderByCommand is present in SelectCommand

Example: SELECT * FROM table ORDER BY column1 ASC; Returns true

SELECT * FROM table; Returns false

func (SelectCommand) HasWhereCommand added in v1.0.0

func (ls SelectCommand) HasWhereCommand() bool

HasWhereCommand - returns true if optional HasWhereCommand is present in SelectCommand

Example: SELECT * FROM table WHERE column1 NOT 'hi'; Returns true

SELECT * FROM table; Returns false

func (SelectCommand) TokenLiteral

func (ls SelectCommand) TokenLiteral() string

type Sequence

type Sequence struct {
	Commands []Command
}

Sequence - Sequence of operations commands

Example: Commands[0] = SELECT * FROM Customers Commands[1] = WHERE City LIKE '%es%';

func (*Sequence) TokenLiteral

func (p *Sequence) TokenLiteral() string

TokenLiteral - Return first literal in sequence

type SortPattern added in v0.0.2

type SortPattern struct {
	ColumnName token.Token // column name
	Order      token.Token // ASC or DESC
}

SortPattern - Represent in which order declared columns should be sorted

type Space added in v1.0.0

type Space struct {
	ColumnName    token.Token
	AggregateFunc *token.Token
}

Space - part of SelectCommand which is containing either * or a column name with an optional function aggregating it

func (Space) ContainsAggregateFunc added in v1.0.0

func (space Space) ContainsAggregateFunc() bool

ContainsAggregateFunc - return true if space contains AggregateFunc that aggregate columnName or *

func (Space) String added in v1.0.0

func (space Space) String() string

type Tifier added in v0.0.2

type Tifier interface {
	IsIdentifier() bool
	GetToken() token.Token
}

Tifier - Interface that represent Token with string value

Methods:

IsIdentifier - Check if Tifier is Identifier GetToken - return token within Tifier

type UpdateCommand added in v1.0.0

type UpdateCommand struct {
	Token        token.Token
	Name         Identifier                    // ex. name of table
	Changes      map[token.Token]Anonymitifier // column names with new values
	WhereCommand *WhereCommand                 // optional
}

UpdateCommand - Part of Command that allow to change existing data

Example: UPDATE table SET col1 TO 2 WHERE column1 NOT 'hi';

func (UpdateCommand) CommandNode added in v1.0.0

func (ls UpdateCommand) CommandNode()

func (UpdateCommand) HasWhereCommand added in v1.0.0

func (ls UpdateCommand) HasWhereCommand() bool

HasWhereCommand - returns true if optional HasWhereCommand is present in UpdateCommand

Example: UPDATE table SET col1 TO 2 WHERE column1 NOT 'hi'; Returns true

UPDATE table SET col1 TO 2; Returns false

func (UpdateCommand) TokenLiteral added in v1.0.0

func (ls UpdateCommand) TokenLiteral() string

type WhereCommand added in v0.0.2

type WhereCommand struct {
	Token      token.Token
	Expression Expression
}

WhereCommand - Part of Command that represent Where statement with expression that will qualify values from Select

Example: WHERE column1 NOT 'goodbye' OR column2 EQUAL 3;

func (WhereCommand) CommandNode added in v0.0.2

func (ls WhereCommand) CommandNode()

func (WhereCommand) TokenLiteral added in v0.0.2

func (ls WhereCommand) TokenLiteral() string

Jump to

Keyboard shortcuts

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