ast

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 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 - Type of Expression that represent single boolean value

Example: TRUE

func (BooleanExpression) ExpressionNode added in v0.0.2

func (ls BooleanExpression) ExpressionNode()

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 - Type of Expression that represent condition that is comparing value from column to static one

Example: column1 EQUAL 123

func (ConditionExpression) ExpressionNode added in v0.0.2

func (ls ConditionExpression) ExpressionNode()

func (ConditionExpression) GetIdentifiers added in v0.0.2

func (ls ConditionExpression) 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
}

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) TokenLiteral added in v0.0.2

func (ls DeleteCommand) TokenLiteral() string

type Expression

type Expression interface {
	// ExpressionNode TODO: Check if ExpressionNode is needed
	ExpressionNode()
	GetIdentifiers() []*Identifier
}

Expression - Mathematical expression that is used to evaluate conditions

Methods:

ExpressionNode: Abstraction needed for creating tree abstraction in order to optimise evaluating GetIdentifiers - Return array of pointers 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 Node

type Node interface {
	TokenLiteral() string
}

Node is connector between commands and expressions

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 - Type of Expression that represent 2 other Expressions and conditional operation

Example: TRUE OR FALSE

func (OperationExpression) ExpressionNode added in v0.0.2

func (ls OperationExpression) ExpressionNode()

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
	Space []token.Token // ex. column names
}

SelectCommand - Part of Command that represent selecting values from tables

Example: SELECT one, two FROM table1;

func (SelectCommand) CommandNode

func (ls SelectCommand) CommandNode()

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 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 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