parser

package
v0.0.0-...-bbea46d Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UNSUPPORTED = "N/A"
	SELECT      = "SELECT"
	FROM        = "FROM"
	WHERE       = "WHERE"
	LIMIT       = "LIMIT"
	INSERT      = "INSERT"
	INTO        = "INTO"
	VALUES      = "VALUES"
	ASTERISK    = "*"
)

SQL type tokens

Variables

This section is empty.

Functions

This section is empty.

Types

type InsertTree

type InsertTree struct {
	Table   string
	Columns []string
	Values  [][]string
}

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

func (*Parser) GetSQLType

func (p *Parser) GetSQLType(sql string) StatementType

func (*Parser) ParseInsert

func (p *Parser) ParseInsert(insert string) (ast *InsertTree, err error)

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

func (p *Parser) ParseSelect(sel string) (ast *SelectTree, err error)

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 SelectTree

type SelectTree struct {
	Projects []string
	Table    string
	Where    []string
	Limit    int64
}

type StatementType

type StatementType string

Jump to

Keyboard shortcuts

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