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

Function buildImports

internal/codegen/golang/imports.go:163–247  ·  view source on GitHub ↗
(options *opts.Options, queries []Query, uses func(string) bool)

Source from the content-addressed store, hash-verified

161}
162
163func buildImports(options *opts.Options, queries []Query, uses func(string) bool) (map[string]struct{}, map[ImportSpec]struct{}) {
164 pkg := make(map[ImportSpec]struct{})
165 std := make(map[string]struct{})
166
167 if uses("sql.Null") {
168 std["database/sql"] = struct{}{}
169 }
170
171 sqlpkg := parseDriver(options.SqlPackage)
172 for _, q := range queries {
173 if q.Cmd == metadata.CmdExecResult {
174 switch sqlpkg {
175 case opts.SQLDriverPGXV4:
176 pkg[ImportSpec{Path: "github.com/jackc/pgconn"}] = struct{}{}
177 case opts.SQLDriverPGXV5:
178 pkg[ImportSpec{Path: "github.com/jackc/pgx/v5/pgconn"}] = struct{}{}
179 default:
180 std["database/sql"] = struct{}{}
181 }
182 }
183 }
184
185 for typeName, pkg := range stdlibTypes {
186 if uses(typeName) {
187 std[pkg] = struct{}{}
188 }
189 }
190
191 if uses("pgtype.") {
192 if sqlpkg == opts.SQLDriverPGXV5 {
193 pkg[ImportSpec{Path: "github.com/jackc/pgx/v5/pgtype"}] = struct{}{}
194 } else {
195 pkg[ImportSpec{Path: "github.com/jackc/pgtype"}] = struct{}{}
196 }
197 }
198
199 for typeName := range pqtypeTypes {
200 if uses(typeName) {
201 pkg[ImportSpec{Path: "github.com/sqlc-dev/pqtype"}] = struct{}{}
202 break
203 }
204 }
205
206 overrideTypes := map[string]string{}
207 for _, override := range options.Overrides {
208 o := override.ShimOverride
209 if o.GoType.BasicType || o.GoType.TypeName == "" {
210 continue
211 }
212 overrideTypes[o.GoType.TypeName] = o.GoType.ImportPath
213 }
214
215 _, overrideNullTime := overrideTypes["pq.NullTime"]
216 if uses("pq.NullTime") && !overrideNullTime {
217 pkg[ImportSpec{Path: "github.com/lib/pq"}] = struct{}{}
218 }
219 _, overrideUUID := overrideTypes["uuid.UUID"]
220 if uses("uuid.UUID") && !overrideUUID {

Callers 5

interfaceImportsMethod · 0.85
modelImportsMethod · 0.85
queryImportsMethod · 0.85
copyfromImportsMethod · 0.85
batchImportsMethod · 0.85

Calls 1

parseDriverFunction · 0.85

Tested by

no test coverage detected