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

Method GetColumnNames

internal/engine/postgresql/analyzer/analyze.go:525–547  ·  view source on GitHub ↗

GetColumnNames implements the expander.ColumnGetter interface. It prepares a query and returns the column names from the result set description.

(ctx context.Context, query string)

Source from the content-addressed store, hash-verified

523// GetColumnNames implements the expander.ColumnGetter interface.
524// It prepares a query and returns the column names from the result set description.
525func (a *Analyzer) GetColumnNames(ctx context.Context, query string) ([]string, error) {
526 if a.pool == nil {
527 return nil, fmt.Errorf("database connection not initialized")
528 }
529
530 conn, err := a.pool.Acquire(ctx)
531 if err != nil {
532 return nil, err
533 }
534 defer conn.Release()
535
536 desc, err := conn.Conn().Prepare(ctx, "", query)
537 if err != nil {
538 return nil, err
539 }
540
541 columns := make([]string, len(desc.Fields))
542 for i, field := range desc.Fields {
543 columns[i] = field.Name
544 }
545
546 return columns, nil
547}

Callers

nothing calls this directly

Implementers 3

CachedAnalyzerinternal/analyzer/analyzer.go
Analyzerinternal/engine/postgresql/analyzer/an
Analyzerinternal/engine/sqlite/analyzer/analyz

Calls 1

PrepareMethod · 0.65

Tested by

no test coverage detected