mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-15 07:18:04 +00:00
i used this script, a little clunky but it got the job done
```bash
for file in `find . -type f -print | grep '\.go'`; do
sed '1,/^\/\/ limitations under the License.$/d' $file > $file.tmp;
result=`cat $file.tmp`
if [[ result != "" ]]; then
gofmt $file.tmp &> /dev/null;
if [[ $? == 0 ]]; then
mv $file.tmp $file && gofmt -w $file;
else
rm $file.tmp;
fi
else
rm $file.tmp;
fi
done
```
46 lines
782 B
Go
46 lines
782 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/molecula/featurebase/v2/sql2"
|
|
)
|
|
|
|
func main() {
|
|
if err := run(context.Background(), os.Args[1:]); err == flag.ErrHelp {
|
|
os.Exit(1)
|
|
} else if err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func run(ctx context.Context, args []string) error {
|
|
fs := flag.NewFlagSet("featurebase-parse-sql", flag.ContinueOnError)
|
|
if err := fs.Parse(args); err != nil {
|
|
return err
|
|
}
|
|
|
|
q := fs.Arg(0)
|
|
if q == "" {
|
|
return fmt.Errorf("query required")
|
|
}
|
|
|
|
stmt, err := sql2.NewParser(strings.NewReader(q)).ParseStatement()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
buf, err := json.MarshalIndent(stmt, "", " ")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Println(string(buf))
|
|
|
|
return nil
|
|
}
|