@@ -15,7 +15,6 @@ import (
15
15
16
16
_ "github.com/go-sql-driver/mysql"
17
17
"github.com/google/cel-go/cel"
18
- "github.com/google/cel-go/common/types/ref"
19
18
"github.com/google/cel-go/ext"
20
19
"github.com/jackc/pgx/v5"
21
20
_ "github.com/mattn/go-sqlite3"
@@ -53,17 +52,6 @@ func NewCmdVet() *cobra.Command {
53
52
}
54
53
}
55
54
56
- type emptyProgram struct {
57
- }
58
-
59
- func (e * emptyProgram ) Eval (any ) (ref.Val , * cel.EvalDetails , error ) {
60
- return nil , nil , fmt .Errorf ("unimplemented" )
61
- }
62
-
63
- func (e * emptyProgram ) ContextEval (ctx context.Context , a any ) (ref.Val , * cel.EvalDetails , error ) {
64
- return e .Eval (a )
65
- }
66
-
67
55
func Vet (ctx context.Context , e Env , dir , filename string , stderr io.Writer ) error {
68
56
configPath , conf , err := readConfig (stderr , dir , filename )
69
57
if err != nil {
@@ -99,9 +87,7 @@ func Vet(ctx context.Context, e Env, dir, filename string, stderr io.Writer) err
99
87
return fmt .Errorf ("new env: %s" , err )
100
88
}
101
89
102
- checks := map [string ]cel.Program {
103
- RuleDbPrepare : & emptyProgram {},
104
- }
90
+ checks := map [string ]cel.Program {}
105
91
msgs := map [string ]string {}
106
92
107
93
for _ , c := range conf .Rules {
@@ -198,7 +184,8 @@ type dbPreparer struct {
198
184
}
199
185
200
186
func (p * dbPreparer ) Prepare (ctx context.Context , name , query string ) error {
201
- _ , err := p .db .PrepareContext (ctx , query )
187
+ s , err := p .db .PrepareContext (ctx , query )
188
+ s .Close ()
202
189
return err
203
190
}
204
191
@@ -316,12 +303,15 @@ func (c *checker) checkSQL(ctx context.Context, s config.SQL) error {
316
303
continue
317
304
}
318
305
original := result .Queries [i ]
319
- if prepareable (s , original .RawStmt ) {
320
- name := fmt .Sprintf ("sqlc_vet_%d_%d" , time .Now ().Unix (), i )
321
- if err := prep .Prepare (ctx , name , query .Text ); err != nil {
322
- fmt .Fprintf (c .Stderr , "%s: %s: %s: error preparing query: %s\n " , query .Filename , q .Name , name , err )
323
- errored = true
324
- }
306
+ if ! prepareable (s , original .RawStmt ) {
307
+ fmt .Fprintf (c .Stderr , "%s: %s: %s: error preparing query: %s\n " , query .Filename , q .Name , name , "query type is unpreparable" )
308
+ errored = true
309
+ continue
310
+ }
311
+ name := fmt .Sprintf ("sqlc_vet_%d_%d" , time .Now ().Unix (), i )
312
+ if err := prep .Prepare (ctx , name , query .Text ); err != nil {
313
+ fmt .Fprintf (c .Stderr , "%s: %s: %s: error preparing query: %s\n " , query .Filename , q .Name , name , err )
314
+ errored = true
325
315
}
326
316
continue
327
317
}
0 commit comments