ruiaylin / sqlparser

SqlParser implement in golang , from TiDB ( PingCap ) , you can use this module independently
Apache License 2.0
48 stars 12 forks source link

how to parse a query #3

Open haroroda opened 7 years ago

haroroda commented 7 years ago

Hi how can i parse a query and get every part of the query and its name? i.e. query1: INSERT INTO QBAdminGroup.abmc_contacts(id, name) VALUES (1, 'jimmy') output1: 'DML', 'Keyword', 'Identifier', 'Keyword', 'Parenthesis' query2: select 2 from admin output2: 'DML', 'Integer', 'Keyword', 'Keyword'

the query part's name no need to be the same as the outputs,but i wonder if sqlparser has similar function or something else.Thanks!

ruiaylin commented 6 years ago

The parser will process the SQL to a AST statement object. The type is in the list { DeleteStmt , InsertStmt, UnionStmt ,UpdateStmt, SelectStmt, ShowStmt ... } . Every statement is a struct , you can decode the struct to get the format you want.