MCPcopy Index your code
hub / github.com/sqlc-dev/sqlc / checkSQL

Method checkSQL

internal/cmd/vet.go:465–675  ·  view source on GitHub ↗
(ctx context.Context, s config.SQL)

Source from the content-addressed store, hash-verified

463}
464
465func (c *checker) checkSQL(ctx context.Context, s config.SQL) error {
466 // TODO: Create a separate function for this logic so we can
467 combo := config.Combine(*c.Conf, s)
468
469 // TODO: This feels like a hack that will bite us later
470 joined := make([]string, 0, len(s.Schema))
471 for _, s := range s.Schema {
472 joined = append(joined, filepath.Join(c.Dir, s))
473 }
474 s.Schema = joined
475
476 joined = make([]string, 0, len(s.Queries))
477 for _, q := range s.Queries {
478 joined = append(joined, filepath.Join(c.Dir, q))
479 }
480 s.Queries = joined
481
482 var name string
483 parseOpts := opts.Parser{
484 Debug: debug.Debug,
485 }
486
487 result, failed := parse(ctx, name, c.Dir, s, combo, parseOpts, c.Stderr)
488 if failed {
489 return ErrFailedChecks
490 }
491
492 var prep preparer
493 var expl explainer
494 if s.Database != nil { // TODO only set up a database connection if a rule evaluation requires it
495 if s.Database.URI != "" && c.OnlyManagedDB {
496 return fmt.Errorf("database: connections disabled via SQLCDEBUG=databases=managed")
497 }
498 dburl, cleanup, err := c.fetchDatabaseUri(ctx, s)
499 if err != nil {
500 return err
501 }
502 defer func() {
503 if err := cleanup(); err != nil {
504 fmt.Fprintf(c.Stderr, "error cleaning up: %s\n", err)
505 }
506 }()
507
508 switch s.Engine {
509 case config.EnginePostgreSQL:
510 conn, err := pgx.Connect(ctx, dburl)
511 if err != nil {
512 return fmt.Errorf("database: connection error: %s", err)
513 }
514 if err := conn.Ping(ctx); err != nil {
515 return fmt.Errorf("database: connection error: %s", err)
516 }
517 defer conn.Close(ctx)
518 pConn := &pgxConn{conn}
519 prep = pConn
520 expl = pConn
521 case config.EngineMySQL:
522 db, err := sql.Open("mysql", dburl)

Callers 1

VetFunction · 0.95

Calls 15

fetchDatabaseUriMethod · 0.95
PrepareMethod · 0.95
ExplainMethod · 0.95
CombineFunction · 0.92
GlobFunction · 0.92
RemoveRollbackStatementsFunction · 0.92
DumpAsJSONFunction · 0.92
parseFunction · 0.85
isInMemorySQLiteFunction · 0.85
codeGenRequestFunction · 0.85
vetConfigFunction · 0.85
vetQueryFunction · 0.85

Tested by

no test coverage detected