Documentation ¶
Overview ¶
Example ¶
package main import ( "fmt" "encoding/json" sql "github.com/krasun/gosqlparser" ) func main() { query, err := sql.Parse("SELECT col1, col2 FROM table1 WHERE col1 == \"abc\" AND col3 == 5 LIMIT 10") if err != nil { fmt.Printf("unexpected error: %s", err) return } json, err := json.Marshal(query) if err != nil { fmt.Printf("unexpected error: %s", err) return } fmt.Println(string(json)) }
Output: {"Table":"table1","Columns":["col1","col2"],"Where":{"Expr":{"Left":{"Left":{"Name":"col1"},"Operator":0,"Right":{"Value":"\"abc\""}},"Operator":1,"Right":{"Left":{"Name":"col3"},"Operator":0,"Right":{"Value":"5"}}}},"Limit":"10"}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ColumnDefinition ¶
type ColumnDefinition struct { Name string Type ColumnType }
ColumnDefinition represents the column definition for CREATE TABLE query.
type ColumnType ¶
type ColumnType int
ColumnType for predefined column types.
const ( // TypeInteger is an integer type of the column. TypeInteger ColumnType = iota // TypeString is a string type of the column. TypeString )
func (ColumnType) Name ¶ added in v1.0.4
func (t ColumnType) Name() string
Name returns the name of the type represented as a string.
type CreateTable ¶
type CreateTable struct { Name string Columns []ColumnDefinition Engine EngineType }
CreateTable represents CREATE TABLE statement.
func (*CreateTable) GetType ¶ added in v1.0.3
func (*CreateTable) GetType() StatementType
GetType returns the statement type.
type Delete ¶
Delete represents DELETE query.
DELETE FROM Table WHERE ...
func (*Delete) GetType ¶ added in v1.0.3
func (*Delete) GetType() StatementType
GetType returns the statement type.
type DropTable ¶
type DropTable struct {
Table string
}
DropTable represents DROP TABLE statement.
func (*DropTable) GetType ¶ added in v1.0.3
func (*DropTable) GetType() StatementType
GetType returns the statement type.
type EngineType ¶ added in v1.0.5
type EngineType int
EngineType
const ( // EngineDefault means that engine is not specified and default one can be used. EngineDefault EngineType = iota // EngineLSM defines LSM-tree engine. EngineLSM EngineType = iota // EngineBPTree defines B+ tree engine. EngineBPTree )
type Expr ¶
type Expr interface {
// contains filtered or unexported methods
}
Expr represents expression that can be used in WHERE statement.
type ExprIdentifier ¶
type ExprIdentifier struct {
Name string
}
ExprIdentifier holds the name of the identifier.
type ExprOperation ¶
ExprOperation represents operation with == or AND operators.
type ExprValueInteger ¶
type ExprValueInteger struct {
Value string
}
ExprValueInteger holds the integer value.
type ExprValueString ¶
type ExprValueString struct {
Value string
}
ExprValueString holds the string value.
type Insert ¶
Insert represents INSERT query.
func (*Insert) GetType ¶ added in v1.0.3
func (*Insert) GetType() StatementType
GetType returns the statement type.
type Select ¶
Select represents parsed SELECT SQL statement.
func (*Select) GetType ¶ added in v1.0.3
func (*Select) GetType() StatementType
GetType returns the statement type.
type Statement ¶
type Statement interface { // GetType returns the statement type. GetType() StatementType }
Statement represents parsed SQL statement. Can be one of Select, Insert, Update, Delete, CreateTable or DropTable.
type StatementType ¶ added in v1.0.3
type StatementType int
const ( // StatementSelect for SELECT query StatementSelect StatementType = iota // StatementUpdate for UPDATE query StatementUpdate // StatementInsert for INSERT query StatementInsert // StatementDelete for DELETE query StatementDelete // StatementCreateTable for CREATE TABLE query StatementCreateTable // StatementDropTable for DROP TABLE query StatementDropTable )