github.com/vedadiyan/sqlparser@v1.0.0/test/parse_test.go (about) 1 package test 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/vedadiyan/sqlparser/pkg/sqlparser" 8 ) 9 10 func TestParse(t *testing.T) { 11 queries := []string{ 12 "SELECT * FROM table_name;", 13 "SELECT column1, column2 FROM table_name;", 14 "SELECT * FROM table_name WHERE column_name = 'value';", 15 "SELECT COUNT(*) FROM table_name;", 16 "SELECT column1, COUNT(*) FROM table_name GROUP BY column1;", 17 "SELECT column1, AVG(column2) FROM table_name GROUP BY column1;", 18 "SELECT column1, MAX(column2) FROM table_name GROUP BY column1;", 19 "SELECT column1, MIN(column2) FROM table_name GROUP BY column1;", 20 "SELECT * FROM table_name ORDER BY column1 DESC;", 21 "SELECT column1, column2 FROM table_name WHERE column1 LIKE 'a%';", 22 "SELECT column1, column2 FROM table_name WHERE column1 IN (1, 2, 3);", 23 "SELECT column1, column2 FROM table_name WHERE column1 BETWEEN 1 AND 10;", 24 "SELECT column1, column2 FROM table_name WHERE column1 IS NULL;", 25 "SELECT column1, column2 FROM table_name WHERE column1 IS NOT NULL;", 26 "SELECT column1, column2 FROM table_name WHERE column1 = (SELECT column1 FROM other_table WHERE column2 = 'value');", 27 "WITH cte_name AS (SELECT column1, column2 FROM table_name WHERE column1 = 'value') SELECT * FROM cte_name;", 28 "SELECT column1, column2, CASE WHEN column1 = 'value' THEN 'yes' ELSE 'no' END AS new_column FROM table_name;", 29 "SELECT column1, column2 FROM table_name WHERE BINARY column1 = 'Value';", 30 "SELECT column1, column2 FROM table_name WHERE column1 + column2 > 100;", 31 "SELECT column1, column2 FROM table_name WHERE NOT (column1 = 'value' AND column2 = 100);", 32 "SELECT * FROM table1 JOIN table2 ON table1.column = table2.column;", 33 "SELECT * FROM table1 LEFT JOIN table2 ON table1.column = table2.column;", 34 "SELECT * FROM table1 RIGHT JOIN table2 ON table1.column = table2.column;", 35 "SELECT * FROM table1 JOIN table2 ON table1.column = table2.column;", 36 "SELECT column1, column2 FROM table1 UNION SELECT column1, column2 FROM table2;", 37 "SELECT * FROM table_name LIMIT 10 OFFSET 5;", 38 "SELECT column1, COUNT(*) FROM table_name GROUP BY column1 HAVING COUNT(*) > 10;", 39 "SELECT column1, column2 FROM table1 INNER JOIN table2 ON table1.column = table2.column WHERE table2.column = 'value';", 40 "SELECT column1, column2 FROM table1 LEFT JOIN table2 ON table1.column = table2.column WHERE table2.column IS NULL;", 41 "SELECT column1, column2 FROM table1 RIGHT JOIN table2 ON table1.column = table2.column WHERE table1.column IS NULL;", 42 } 43 for _, query := range queries { 44 _, err := sqlparser.Parse(query) 45 if err != nil { 46 fmt.Println(query, err.Error()) 47 t.FailNow() 48 } 49 } 50 }