-
Notifications
You must be signed in to change notification settings - Fork 1
/
app_query.go
62 lines (49 loc) · 895 Bytes
/
app_query.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// +build ignore
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"github.com/kardianos/rdb"
_ "github.com/kardianos/rdb/ms"
"github.com/kardianos/rdb/table"
)
func main() {
err := run()
if err != nil {
log.Fatal(err)
}
}
func run() error {
cs := flag.String("connect", "", "Connection string")
queryFile := flag.String("queryfile", "", "Query filename")
flag.Parse()
if len(*cs) == 0 || len(*queryFile) == 0 {
flag.PrintDefaults()
os.Exit(1)
}
query, err := ioutil.ReadFile(*queryFile)
if err != nil {
return err
}
fmt.Println("START")
config, err := rdb.ParseConfigURL(*cs)
if err != nil {
return err
}
db, err := rdb.Open(config)
if err != nil {
return err
}
defer db.Close()
t, err := table.FillCommand(db, &rdb.Command{
Sql: string(query),
})
if err != nil {
return err
}
fmt.Println("Rows: ", len(t.Row))
return nil
}