statement

package
v0.0.0-...-bbac96e Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2020 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

tongue-demon. A cli tool to generate go code from your sql code. Copyright (C) 2020 Rotten Network

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

tongue-demon. A cli tool to generate go code from your sql code. Copyright (C) 2020 Rotten Network

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

tongue-demon. A cli tool to generate go code from your sql code. Copyright (C) 2020 Rotten Network

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	Name       string
	Type       ColumnType
	Length     int
	Nullable   bool
	KeyType    KeyType
	Constrains []Constraint
	Default    string
	References string //if foreign key ,Table name reference
	Extras     []string
}

type ColumnCateg

type ColumnCateg int
const (
	UnknownCategory ColumnCateg = iota
	Integer
	Float
	Boolean
	String
	Date
)

type ColumnType

type ColumnType interface {
	GetName() string
	GetCateg() ColumnCateg
}

type Condition

type Condition struct {
	Operand1 string
	Operator Operator
	Operand2 string
}

type Constraint

type Constraint int
const (
	NoConstraint Constraint = iota
	Unique
)

type ExpressionNode

type ExpressionNode struct {
	Lchild    *ExpressionNode
	Rchild    *ExpressionNode
	Parent    *ExpressionNode
	Evaluated bool
	IsUnique  bool
	Type      NodeType
	Val       string
}

func NewExpressionNode

func NewExpressionNode(val string, Type NodeType) *ExpressionNode

func (*ExpressionNode) PushNode

func (n *ExpressionNode) PushNode(node *ExpressionNode)

type Join

type Join struct {
	Table      *Table
	Conditions []*Condition
}

type KeyType

type KeyType int
const (
	NoKey          KeyType = -1
	UnknownKeyType KeyType = iota
	SuperKey
	CandidateKey
	PrimaryKey
	AlternateKey
	CompositeKey
	ForeignKey
)

type NodeType

type NodeType int
const (
	Operand NodeType = iota
	BinaryOperator
	AND
	OR
	IN
	EQUALS
)

type Operator

type Operator int
const (
	UnknownOperator Operator = iota
	// Eq -> "="
	Eq
	// Ne -> "!="
	Ne
	// Gt -> ">"
	Gt
	// Lt -> "<"
	Lt
	// Gte -> ">="
	Gte
	// Lte -> "<="
	Lte
	// In =>IN
	In
)

func GetOperator

func GetOperator(s string) Operator

type Parameter

type Parameter struct {
	Name string
	Type ColumnCateg
}

type RelationType

type RelationType int
const (
	Unknown RelationType = iota
	OneToOne
	OneToMany
	ManyToMany
)

type Statement

type Statement struct {
	Type               Type
	Table              *Table  //Root Table
	Joins              []*Join //All statement Joins
	Columns            []*Column
	Conditions         []*Condition
	Updates            []*UpdateField
	InsertSets         []*[]string
	Fields             []string //Used for SELECT
	Children           []*Statement
	RootExpressionNode *ExpressionNode
	Parent             *Statement
}

Statement represents a parsed query

func NewStatement

func NewStatement() *Statement

func (*Statement) AddChild

func (s *Statement) AddChild(cs *Statement)

func (*Statement) AddColumn

func (s *Statement) AddColumn(cl *Column)

func (*Statement) AddCondition

func (s *Statement) AddCondition(cond *Condition)

func (*Statement) AddField

func (s *Statement) AddField(f string)

func (*Statement) AddInsert

func (s *Statement) AddInsert(is *[]string)

func (*Statement) AddJoin

func (s *Statement) AddJoin(join *Join)

func (*Statement) AddUpdate

func (s *Statement) AddUpdate(u *UpdateField)

func (*Statement) FindColumns

func (s *Statement) FindColumns(field string, term interface{}) []*Column

func (*Statement) GetChildren

func (s *Statement) GetChildren() []*Statement

func (*Statement) GetColumns

func (s *Statement) GetColumns() []*Column

func (*Statement) GetConditions

func (s *Statement) GetConditions() []*Condition

func (*Statement) GetFields

func (s *Statement) GetFields() []string

func (*Statement) GetInserts

func (s *Statement) GetInserts() []*[]string

func (*Statement) GetJoinByNameOrAlias

func (s *Statement) GetJoinByNameOrAlias(a string) *Join

func (*Statement) GetJoins

func (s *Statement) GetJoins() []*Join

func (*Statement) GetParent

func (s *Statement) GetParent() *Statement

func (*Statement) GetTable

func (s *Statement) GetTable() *Table

func (*Statement) GetUpdates

func (s *Statement) GetUpdates() []*UpdateField

func (*Statement) SetColumns

func (s *Statement) SetColumns(c []*Column)

func (*Statement) SetConditions

func (s *Statement) SetConditions(conditions []*Condition)

func (*Statement) SetParent

func (s *Statement) SetParent(ps *Statement)

func (*Statement) SetTable

func (s *Statement) SetTable(table *Table) *Table

type Table

type Table struct {
	Name, Alias string
}

func SearchJoinsOrTable

func SearchJoinsOrTable(s *Statement, identifier string) *Table

SearchJoinsOrTable searches statement recursively for Table reference

type Type

type Type int
const (
	UnknownQueryType Type = iota
	Create
	Select
	Update
	Insert
	Delete
	Alter
)

type UpdateField

type UpdateField struct {
	Column string
	Value  string
}

Jump to

Keyboard shortcuts

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