-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from goccy/group_by
Supports HAVING / ORDER BY / GROUP BY (ROLLUP) / QUALIFY / JOIN and some window functions
- Loading branch information
Showing
22 changed files
with
1,429 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module github.com/goccy/go-zetasqlite/cmd/zetasqlite-cli | ||
|
||
go 1.18 | ||
|
||
require ( | ||
github.com/chzyer/readline v1.5.1 | ||
github.com/goccy/go-zetasqlite v0.3.1 | ||
) | ||
|
||
require ( | ||
github.com/goccy/go-zetasql v0.2.8 // indirect | ||
github.com/mattn/go-sqlite3 v1.14.14 // indirect | ||
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
github.com/chzyer/logex v1.2.1 h1:XHDu3E6q+gdHgsdTPH6ImJMIp436vR6MPtH8gP05QzM= | ||
github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ= | ||
github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI= | ||
github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk= | ||
github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04= | ||
github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8= | ||
github.com/goccy/go-zetasql v0.2.8 h1:Kh8zQgBxN7Kg+cNJ3Z724G0oyaGoUYngeATSp6IOF/A= | ||
github.com/goccy/go-zetasql v0.2.8/go.mod h1:6W14CJVKh7crrSPyj6NPk4c49L2NWnxvyDLsRkOm4BI= | ||
github.com/goccy/go-zetasqlite v0.3.1 h1:rOWZZrQp59iu0FLeYkrOjdXBQbF/XPKNq3wGdbsTNYE= | ||
github.com/goccy/go-zetasqlite v0.3.1/go.mod h1:PT3M02F7jVGdLmrczfr3ZaLnjxH9bowlsP6qy77OG1g= | ||
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= | ||
github.com/mattn/go-sqlite3 v1.14.14 h1:qZgc/Rwetq+MtyE18WhzjokPD93dNqLGNT3QJuLvBGw= | ||
github.com/mattn/go-sqlite3 v1.14.14/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= | ||
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 h1:y/woIyUBFbpQGKS0u1aHF/40WUDnek3fPOyD08H5Vng= | ||
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"fmt" | ||
"io" | ||
"log" | ||
"reflect" | ||
"strings" | ||
|
||
"github.com/chzyer/readline" | ||
_ "github.com/goccy/go-zetasqlite" | ||
) | ||
|
||
func main() { | ||
if err := run(context.Background()); err != nil { | ||
log.Fatalf("%+v", err) | ||
} | ||
} | ||
|
||
func run(ctx context.Context) error { | ||
db, err := sql.Open("zetasqlite_sqlite3", ":memory:") | ||
if err != nil { | ||
return err | ||
} | ||
rl, err := readline.NewEx(&readline.Config{ | ||
Prompt: ">> ", | ||
HistoryFile: "./zetasqlite.history", | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
defer rl.Close() | ||
for { | ||
line, err := rl.Readline() | ||
if err == io.EOF || err == readline.ErrInterrupt { | ||
break | ||
} | ||
line = strings.TrimSpace(line) | ||
rows, err := db.QueryContext(ctx, line) | ||
if err != nil { | ||
fmt.Printf("ERROR: %v\n", err) | ||
continue | ||
} | ||
columns, err := rows.Columns() | ||
if err != nil { | ||
fmt.Printf("ERROR: %v\n", err) | ||
continue | ||
} | ||
columnNum := len(columns) | ||
args := make([]interface{}, columnNum) | ||
for i := 0; i < columnNum; i++ { | ||
var v interface{} | ||
args[i] = &v | ||
} | ||
header := strings.Join(columns, "|") | ||
fmt.Printf("%s\n", header) | ||
fmt.Printf("%s\n", strings.Repeat("-", len(header))) | ||
for rows.Next() { | ||
if err := rows.Scan(args...); err != nil { | ||
fmt.Printf("ERROR: %v", err) | ||
break | ||
} | ||
values := make([]string, 0, len(args)) | ||
for _, arg := range args { | ||
v := reflect.ValueOf(arg).Elem().Interface() | ||
values = append(values, fmt.Sprint(v)) | ||
} | ||
fmt.Printf("%s\n", strings.Join(values, "|")) | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.