/
execute.go
67 lines (56 loc) · 1.48 KB
/
execute.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
63
64
65
66
67
package cmd
import (
"context"
"fmt"
"time"
"github.com/spf13/cobra"
)
var ExecuteCmd = &cobra.Command{
Use: "execute",
Short: "execute",
RunE: func(cmd *cobra.Command, args []string) error {
return fmt.Errorf("Command name argument expected.")
},
}
// executeStalenessSQLCmd is ExactStaleness を実行する
func executeStalenessSQLCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "staleness",
Short: "Execute SQL with ExactStaleness (before 15sec)",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
db, err := SpannerDatabase()
if err != nil {
return err
}
ss, err := NewSpannerService(ctx, db)
if err != nil {
return fmt.Errorf("%s : %s", err.Error(), db)
}
return ss.ExactStalenessQuery(ctx, sql)
},
}
return cmd
}
// executeUpdateSQLCmd is 更新系の DML を実行する
// OperationPITR Table への INSERT も同時に行うことで、クエリ実行時のCommitTimestampを分かりやすくしている
func executeUpdateSQLCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "update",
Short: "",
RunE: func(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
defer cancel()
db, err := SpannerDatabase()
if err != nil {
return err
}
ss, err := NewSpannerService(ctx, db)
if err != nil {
return fmt.Errorf("%s : %s", err.Error(), db)
}
return ss.ExecuteUpdateDML(ctx, sql)
},
}
return cmd
}