@@ -23,6 +23,7 @@ import (
2323 "github.com/kyleconroy/sqlc/internal/debug"
2424 "github.com/kyleconroy/sqlc/internal/opts"
2525 "github.com/kyleconroy/sqlc/internal/plugin"
26+ "github.com/kyleconroy/sqlc/internal/shfmt"
2627 "github.com/kyleconroy/sqlc/internal/sql/ast"
2728)
2829
@@ -107,21 +108,9 @@ func Vet(ctx context.Context, e Env, dir, filename string, stderr io.Writer) err
107108 msgs [c .Name ] = c .Msg
108109 }
109110
110- dbenv , err := cel .NewEnv (
111- cel .StdLib (),
112- ext .Strings (ext .StringsVersion (1 )),
113- cel .Variable ("env" ,
114- cel .MapType (cel .StringType , cel .StringType ),
115- ),
116- )
117- if err != nil {
118- return fmt .Errorf ("new dbenv; %s" , err )
119- }
120-
121111 c := checker {
122112 Checks : checks ,
123113 Conf : conf ,
124- Dbenv : dbenv ,
125114 Dir : dir ,
126115 Env : env ,
127116 Envmap : map [string ]string {},
@@ -197,41 +186,22 @@ func (p *dbPreparer) Prepare(ctx context.Context, name, query string) error {
197186type checker struct {
198187 Checks map [string ]cel.Program
199188 Conf * config.Config
200- Dbenv * cel.Env
201189 Dir string
202190 Env * cel.Env
203191 Envmap map [string ]string
204192 Msgs map [string ]string
205193 Stderr io.Writer
206194}
207195
208- func (c * checker ) DSN (expr string ) (string , error ) {
209- ast , issues := c .Dbenv .Compile (expr )
210- if issues != nil && issues .Err () != nil {
211- return "" , fmt .Errorf ("type-check error: database url %s" , issues .Err ())
212- }
213- prg , err := c .Dbenv .Program (ast )
214- if err != nil {
215- return "" , fmt .Errorf ("program construction error: database url %s" , err )
216- }
196+ func (c * checker ) DSN (dsn string ) (string , error ) {
217197 // Populate the environment variable map if it is empty
218198 if len (c .Envmap ) == 0 {
219199 for _ , e := range os .Environ () {
220200 k , v , _ := strings .Cut (e , "=" )
221201 c .Envmap [k ] = v
222202 }
223203 }
224- out , _ , err := prg .Eval (map [string ]any {
225- "env" : c .Envmap ,
226- })
227- if err != nil {
228- return "" , fmt .Errorf ("expression error: %s" , err )
229- }
230- dsn , ok := out .Value ().(string )
231- if ! ok {
232- return "" , fmt .Errorf ("expression returned non-string value: %v" , out .Value ())
233- }
234- return dsn , nil
204+ return shfmt .Replace (dsn , c .Envmap ), nil
235205}
236206
237207func (c * checker ) checkSQL (ctx context.Context , s config.SQL ) error {
@@ -312,9 +282,8 @@ func (c *checker) checkSQL(ctx context.Context, s config.SQL) error {
312282 if prep != nil && prepareable (s , original .RawStmt ) {
313283 name := fmt .Sprintf ("sqlc_vet_%d_%d" , time .Now ().Unix (), i )
314284 if err := prep .Prepare (ctx , name , query .Text ); err != nil {
315- fmt .Fprintf (c .Stderr , "%s: error preparing %s: %s\n " , query .Filename , query .Name , err )
285+ fmt .Fprintf (c .Stderr , "%s: error preparing %s on %s : %s\n " , query .Filename , query .Name , s . Engine , err )
316286 errored = true
317- continue
318287 }
319288 }
320289 q := vetQuery (query )
0 commit comments