-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (46 loc) · 1.34 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"fmt"
"os"
"strings"
sqlParser "github.com/SpaghettiDB/SQL-Parser/Parser"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("Usage: go run main.go <query_type>")
return
}
// Extract the query type from command-line arguments
queryType := strings.ToUpper(os.Args[1])
// create a schema instance from sqlParser package
schema := sqlParser.Schema{}
parser := sqlParser.NewSQLParser(schema)
// Define example queries for each query type
var query string
switch queryType {
case "SELECT":
query = "SELECT a , b, c, d,e FROM Customers WHERE Country = 'USA';"
case "INSERT":
query = "INSERT INTO Customers (CustomerName, ContactName, Country) VALUES ('John Doe', 'John Smith', 'UK');"
case "UPDATE":
query = "UPDATE Customers SET Country = 'Germany' WHERE CustomerID = 1;"
case "DELETE":
query = "DELETE FROM Customers WHERE CustomerID = 1;"
case "DROP":
query = "DROP TABLE Customers;"
case "DROPINDEX":
query = "DROP index Customers;"
case "CREATE":
query = "CREATE TABLE Customers (CustomerID, CustomerName , Country );"
case "CREATEINDEX":
query = "CREATE index index_anme on Customers (CustomerID, CustomerName , Country );"
default:
fmt.Println("Unsupported query type.")
return
}
tokens, err := parser.Tokenize(query)
if err != nil {
panic(err)
}
fmt.Println("Tokens: ", tokens)
}