Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Query To AST parser #202

Open
robinportigliatti opened this issue Nov 22, 2023 · 1 comment
Open

Question: Query To AST parser #202

robinportigliatti opened this issue Nov 22, 2023 · 1 comment

Comments

@robinportigliatti
Copy link

Hello,

How would you parse a query to an AST using sql/ast ?

I tried to find a parse method but couldn't.

The code would look something like:

    query := "SELECT * FROM users WHERE age > 30"

    stmt, err := ast.Parse(query)
    if err != nil {
        fmt.Println("Erreur d'analyse :", err)
        return
    }

    fmt.Printf("AST: %#v\n", stmt)

Robin,

@robinportigliatti
Copy link
Author

I guess that's it ?

package main

import (
    "fmt"
 	"github.com/chrislusf/gleam/sql/parser"
)

func main() {
	sql := "SELECT * FROM users WHERE age > 30"

	p := parser.New()
	tree, err := p.ParseOneStmt(sql, "", "")
	if err != nil {
		fmt.Printf("error")
		return 
	}

    fmt.Printf("AST: %#v\n", tree)

 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant