(options *opts.Options, queries []Query, uses func(string) bool)
| 161 | } |
| 162 | |
| 163 | func 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 { |
no test coverage detected