Documentation
¶
Index ¶
- func ParseDDL(filepath, s string) (ast.DDL, error)
- func ParseDDLs(filepath, s string) ([]ast.DDL, error)
- func ParseDML(filepath, s string) (ast.DML, error)
- func ParseDMLs(filepath, s string) ([]ast.DML, error)
- func ParseExpr(filepath, s string) (ast.Expr, error)
- func ParseQuery(filepath, s string) (*ast.QueryStatement, error)
- func ParseStatement(filepath, s string) (ast.Statement, error)
- func ParseStatements(filepath, s string) ([]ast.Statement, error)
- func ParseType(filepath, s string) (ast.Type, error)
- type Error
- type Lexer
- type MultiError
- type Parser
- func (p *Parser) ParseDDL() (ast.DDL, error)
- func (p *Parser) ParseDDLs() ([]ast.DDL, error)
- func (p *Parser) ParseDML() (ast.DML, error)
- func (p *Parser) ParseDMLs() ([]ast.DML, error)
- func (p *Parser) ParseExpr() (ast.Expr, error)
- func (p *Parser) ParseQuery() (*ast.QueryStatement, error)
- func (p *Parser) ParseStatement() (ast.Statement, error)
- func (p *Parser) ParseStatements() ([]ast.Statement, error)
- func (p *Parser) ParseType() (ast.Type, error)
- type RawStatement
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseDDL ¶
ParseDDL parses an input string containing a DDL statement. filepath can be empty, it is only used in error message.
Example ¶
sql := heredoc.Doc(` CREATE TABLE foo ( x int64, y int64, ) PRIMARY KEY (x) `) ddl, err := memefish.ParseDDL("path/to/file.sql", sql) if err != nil { panic(err) } fmt.Println(ddl.SQL())
Output: CREATE TABLE foo ( x INT64, y INT64 ) PRIMARY KEY (x)
func ParseDDLs ¶
ParseDDLs parses an input string containing DDL statements. filepath can be empty, it is only used in error message.
Example ¶
sql := heredoc.Doc(` CREATE TABLE foo (x int64, y int64) PRIMARY KEY (x); CREATE TABLE bar ( x int64, z int64, ) PRIMARY KEY (x, z), INTERLEAVE IN PARENT foo; `) ddls, err := memefish.ParseDDLs("path/to/file.sql", sql) if err != nil { panic(err) } for _, ddl := range ddls { fmt.Printf("%s;\n", ddl.SQL()) }
Output: CREATE TABLE foo ( x INT64, y INT64 ) PRIMARY KEY (x); CREATE TABLE bar ( x INT64, z INT64 ) PRIMARY KEY (x, z), INTERLEAVE IN PARENT foo;
func ParseDML ¶
ParseDML parses an input string containing a DML statement. filepath can be empty, it is only used in error message.
Example ¶
sql := heredoc.Doc(` INSERT INTO foo (x, y) VALUES (1, 2), (3, 4) `) dml, err := memefish.ParseDML("path/to/file.sql", sql) if err != nil { panic(err) } fmt.Println(dml.SQL())
Output: INSERT INTO foo (x, y) VALUES (1, 2), (3, 4)
func ParseDMLs ¶
ParseDMLs parses an input string containing DML statements. filepath can be empty, it is only used in error message.
Example ¶
sql := heredoc.Doc(` INSERT INTO foo (x, y) VALUES (1, 2), (3, 4); DELETE FROM foo WHERE foo.x = 1 AND foo.y = 2; `) dmls, err := memefish.ParseDMLs("path/to/file.sql", sql) if err != nil { panic(err) } for _, dml := range dmls { fmt.Printf("%s;\n", dml.SQL()) }
Output: INSERT INTO foo (x, y) VALUES (1, 2), (3, 4); DELETE FROM foo WHERE foo.x = 1 AND foo.y = 2;
func ParseExpr ¶
ParseExpr parses an input string containing an expression. filepath can be empty, it is only used in error message.
Example ¶
package main import ( "fmt" "github.com/cloudspannerecosystem/memefish" ) func main() { stmt, err := memefish.ParseExpr("", "a * b") if err != nil { panic(err) } fmt.Println(stmt.SQL()) }
Output: a * b
func ParseQuery ¶
func ParseQuery(filepath, s string) (*ast.QueryStatement, error)
ParseQuery parses an input string containing a query statement. filepath can be empty, it is only used in error message.
Example ¶
package main import ( "fmt" "github.com/cloudspannerecosystem/memefish" ) func main() { stmt, err := memefish.ParseQuery("path/to/file.sql", "SELECT * FROM foo") if err != nil { panic(err) } fmt.Println(stmt.SQL()) }
Output: SELECT * FROM foo
func ParseStatement ¶
ParseStatement parses an input string containing a statement. filepath can be empty, it is only used in error message.
Example ¶
package main import ( "fmt" "github.com/cloudspannerecosystem/memefish" ) func main() { stmt, err := memefish.ParseStatement("path/to/file.sql", "SELECT * FROM foo") if err != nil { panic(err) } fmt.Println(stmt.SQL()) }
Output: SELECT * FROM foo
func ParseStatements ¶
ParseStatements parses an input string containing statements. filepath can be empty, it is only used in error message.
Example ¶
package main import ( "fmt" "github.com/cloudspannerecosystem/memefish" ) func main() { stmts, err := memefish.ParseStatements("path/to/file.sql", "SELECT 1; INSERT foo (x, y) VALUES (1, 2)") if err != nil { panic(err) } for _, stmt := range stmts { fmt.Printf("%s;\n", stmt.SQL()) } }
Output: SELECT 1; INSERT INTO foo (x, y) VALUES (1, 2);
func ParseType ¶
ParseType parses an input string containing a type. filepath can be empty, it is only used in error message.
Example ¶
package main import ( "fmt" "github.com/cloudspannerecosystem/memefish" ) func main() { stmt, err := memefish.ParseType("", "ARRAY<STRUCT<n INT64, s STRING>>") if err != nil { panic(err) } fmt.Println(stmt.SQL()) }
Output: ARRAY<STRUCT<n INT64, s STRING>>
Types ¶
type MultiError ¶
type MultiError []*Error
MultiError is a list of errors occured on parsing.
Note that Parse* methods returns this wrapped error even if the error is just one.
func (MultiError) Error ¶
func (list MultiError) Error() string
Error returns an error message.
This message only shows the first error's message and other errors' messages are omitted. If you want to obtain all messages of errors at once, you can use FullError instead.
func (MultiError) FullError ¶
func (list MultiError) FullError() string
FullError returns a full error message.
func (MultiError) String ¶
func (list MultiError) String() string
type Parser ¶
type Parser struct { *Lexer // contains filtered or unexported fields }
func (*Parser) ParseDDLs ¶
ParseDDLs parses CREATE/ALTER/DROP statements list separated by semi-colon.
func (*Parser) ParseDMLs ¶
ParseDMLs parses INSERT/DELETE/UPDATE statements list separated by semi-colon.
func (*Parser) ParseQuery ¶
func (p *Parser) ParseQuery() (*ast.QueryStatement, error)
ParseQuery parses a query statement.
func (*Parser) ParseStatement ¶
ParseStatement parses a SQL statement.
func (*Parser) ParseStatements ¶
ParseStatements parses SQL statements list separated by semi-colon.
type RawStatement ¶
func SplitRawStatements ¶
func SplitRawStatements(filepath, s string) ([]*RawStatement, error)
SplitRawStatements splits an input string to statement strings at terminating semicolons without parsing. It preserves all comments. Statements are terminated by `;`, `<eof>` or `;<eof>` and the minimum output will be []string{""}. See terminating semicolons. This function won't panic but return error if lexer become error state. filepath can be empty, it is only used in error message.
Directories
¶
Path | Synopsis |
---|---|
Package ast provides AST nodes definitions.
|
Package ast provides AST nodes definitions. |
examples
|
|
tools
|
|
util/poslang
Package poslang provides an implementation of the POS expression.
|
Package poslang provides an implementation of the POS expression. |