MCPcopy
hub / github.com/sqlc-dev/sqlc / scanRelations

Function scanRelations

internal/tools/sqlc-pg-gen/relation.go:53–102  ·  view source on GitHub ↗
(rows pgx.Rows)

Source from the content-addressed store, hash-verified

51}
52
53func scanRelations(rows pgx.Rows) ([]Relation, error) {
54 defer rows.Close()
55 // Iterate through the result set
56 var relations []Relation
57 var prevRel *Relation
58
59 for rows.Next() {
60 var schemaName string
61 var tableName string
62 var columnName string
63 var columnNotNull bool
64 var columnType string
65 var columnLength *int
66 var columnIsArray bool
67 err := rows.Scan(
68 &schemaName,
69 &tableName,
70 &columnName,
71 &columnNotNull,
72 &columnType,
73 &columnLength,
74 &columnIsArray,
75 )
76 if err != nil {
77 return nil, err
78 }
79
80 if prevRel == nil || tableName != prevRel.Name {
81 // We are on the same table, just keep adding columns
82 r := Relation{
83 Catalog: "pg_catalog",
84 SchemaName: schemaName,
85 Name: tableName,
86 }
87
88 relations = append(relations, r)
89 prevRel = &relations[len(relations)-1]
90 }
91
92 prevRel.Columns = append(prevRel.Columns, RelationColumn{
93 Name: columnName,
94 Type: columnType,
95 IsNotNull: columnNotNull,
96 IsArray: columnIsArray,
97 Length: columnLength,
98 })
99 }
100
101 return relations, rows.Err()
102}
103
104func readRelations(ctx context.Context, conn *pgx.Conn, schemaName string) ([]Relation, error) {
105 rows, err := conn.Query(ctx, relationQuery, schemaName)

Callers 1

readRelationsFunction · 0.85

Calls 4

CloseMethod · 0.65
NextMethod · 0.45
ScanMethod · 0.45
ErrMethod · 0.45

Tested by

no test coverage detected