Skip to content

Commit

Permalink
Promotes csvq driver to base drivers
Browse files Browse the repository at this point in the history
In the interest of supporting more base drivers, promoting csvq to a
base driver, as its enables significantly functionality through when
combined with the \copy command.
  • Loading branch information
kenshaw committed Aug 4, 2022
1 parent 913aae9 commit 1a9c3ea
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 107 deletions.
1 change: 0 additions & 1 deletion .github/workflows/homebrew.yml
Expand Up @@ -19,6 +19,5 @@ jobs:
--no-browse \
--force \
--message="Update usql formula to ${{ github.ref_name }}" \
--version="${{ github.ref_name }}" \
--url="https://github.com/xo/usql/archive/${{ github.ref_name }}.tar.gz" \
xo/xo/usql
5 changes: 3 additions & 2 deletions drivers/csvq/csvq.go
@@ -1,6 +1,7 @@
// Package csvq defines and registers usql's CSVQ driver.
//
// See: https://github.com/mithrandie/csvq-driver
// Group: base
package csvq

import (
Expand All @@ -16,6 +17,7 @@ import (
func init() {
csvq.SetStdout(query.NewDiscard())
drivers.Register("csvq", drivers.Driver{
AllowMultilineComments: true,
Process: func(prefix string, sqlstr string) (string, string, bool, error) {
typ, q := drivers.QueryExecType(prefix, sqlstr)
if strings.HasPrefix(prefix, "SHOW") {
Expand All @@ -26,8 +28,7 @@ func init() {
},
Version: func(ctx context.Context, db drivers.DB) (string, error) {
var ver string
err := db.QueryRowContext(ctx, `SELECT @#VERSION`).Scan(&ver)
if err != nil {
if err := db.QueryRowContext(ctx, `SELECT @#VERSION`).Scan(&ver); err != nil {
return "", err
}
return "CSVQ " + ver, nil
Expand Down
17 changes: 15 additions & 2 deletions gen.go
Expand Up @@ -335,22 +335,35 @@ func buildDriverTable() string {
return s + "\n" + buildTableLinks(baseDrivers, mostDrivers, allDrivers)
}

var baseOrder = map[string]int{
"postgres": 0,
"mysql": 1,
"sqlserver": 2,
"oracle": 3,
"sqlite3": 4,
"csvq": 5,
}

func buildRows(m map[string]DriverInfo, widths []int) ([][]string, []int) {
var drivers []DriverInfo
for _, v := range m {
drivers = append(drivers, v)
}
sort.Slice(drivers, func(i, j int) bool {
switch {
case drivers[i].Group == "base":
return baseOrder[drivers[i].Driver] < baseOrder[drivers[j].Driver]
}
return strings.ToLower(drivers[i].Desc) < strings.ToLower(drivers[j].Desc)
})
var rows [][]string
for i, v := range drivers {
notes := ""
if v.CGO {
notes = "<sup>[†][f-cgo]</sup>"
notes = " <sup>[†][f-cgo]</sup>"
}
if v.Wire {
notes = "<sup>[‡][f-wire]</sup>"
notes = " <sup>[‡][f-wire]</sup>"
}
rows = append(rows, []string{
v.Desc,
Expand Down
2 changes: 1 addition & 1 deletion internal/csvq.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1a9c3ea

Please sign in to comment.