aboutsummaryrefslogtreecommitdiff
path: root/internal/postgres/unit.go
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2021-03-04 11:47:40 -0500
committerJonathan Amsterdam <jba@google.com>2021-03-04 20:54:01 +0000
commitc16d5e9c5f440307d9cc4ca393d3ced9f25dbc20 (patch)
treed4fda81ff774e0f0b16b2dc109949a1a6a7cb6f2 /internal/postgres/unit.go
parent7b81365ee8c925d80bbdc4e640bef4e7b7fc8bd7 (diff)
downloadgo-x-pkgsite-c16d5e9c5f440307d9cc4ca393d3ced9f25dbc20.tar.xz
internal/postgres: add collectStrings
Factor out a common pattern by adding a function that collects strings from a query. Change-Id: Ia9ba535e0deddc79cb0566548ab82d1df0cd52ff Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/298731 Trust: Jonathan Amsterdam <jba@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Julie Qiu <julie@golang.org>
Diffstat (limited to 'internal/postgres/unit.go')
-rw-r--r--internal/postgres/unit.go16
1 files changed, 2 insertions, 14 deletions
diff --git a/internal/postgres/unit.go b/internal/postgres/unit.go
index 7ca206a0..aab645ec 100644
--- a/internal/postgres/unit.go
+++ b/internal/postgres/unit.go
@@ -265,22 +265,10 @@ func (db *DB) getUnitID(ctx context.Context, fullPath, modulePath, resolvedVersi
func (db *DB) getImports(ctx context.Context, unitID int) (_ []string, err error) {
defer derrors.WrapStack(&err, "getImports(ctx, %d)", unitID)
defer middleware.ElapsedStat(ctx, "getImports")()
- var imports []string
- collect := func(rows *sql.Rows) error {
- var path string
- if err := rows.Scan(&path); err != nil {
- return fmt.Errorf("row.Scan(): %v", err)
- }
- imports = append(imports, path)
- return nil
- }
- if err := db.db.RunQuery(ctx, `
+ return collectStrings(ctx, db.db, `
SELECT to_path
FROM package_imports
- WHERE unit_id = $1`, collect, unitID); err != nil {
- return nil, err
- }
- return imports, nil
+ WHERE unit_id = $1`, unitID)
}
// getPackagesInUnit returns all of the packages in a unit from a