-
Notifications
You must be signed in to change notification settings - Fork 351
/
presto.go
35 lines (32 loc) · 886 Bytes
/
presto.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
// Package presto defines and registers usql's Presto driver.
//
// See: https://github.com/prestodb/presto-go-client
package presto
import (
"context"
"regexp"
_ "github.com/prestodb/presto-go-client/presto" // DRIVER
"github.com/xo/usql/drivers"
)
func init() {
endRE := regexp.MustCompile(`;?\s*$`)
drivers.Register("presto", drivers.Driver{
AllowMultilineComments: true,
Process: func(prefix string, sqlstr string) (string, string, bool, error) {
sqlstr = endRE.ReplaceAllString(sqlstr, "")
typ, q := drivers.QueryExecType(prefix, sqlstr)
return typ, sqlstr, q, nil
},
Version: func(ctx context.Context, db drivers.DB) (string, error) {
var ver string
err := db.QueryRowContext(
ctx,
`SELECT node_version FROM system.runtime.nodes LIMIT 1`,
).Scan(&ver)
if err != nil {
return "", err
}
return "Presto " + ver, nil
},
})
}