From 5ef1a397279cbf589408ef2bca293602087739f8 Mon Sep 17 00:00:00 2001 From: Johan Brandhorst-Satzkorn Date: Fri, 15 Dec 2023 17:36:08 -0800 Subject: [PATCH] internal/credential: use simpler query arg --- internal/credential/repository_store.go | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/internal/credential/repository_store.go b/internal/credential/repository_store.go index 0ef3c2e642..4ec231cb5b 100644 --- a/internal/credential/repository_store.go +++ b/internal/credential/repository_store.go @@ -7,8 +7,6 @@ import ( "context" "database/sql" "fmt" - "strconv" - "strings" "time" "github.com/hashicorp/boundary/internal/db" @@ -50,15 +48,8 @@ func (s *StoreRepository) List(ctx context.Context, projectIds []string, afterIt return nil, time.Time{}, errors.New(ctx, errors.InvalidParameter, op, "missing limit") } - var inClauses []string - var args []any - for i, projectId := range projectIds { - arg := "project_id_" + strconv.Itoa(i) - inClauses = append(inClauses, "@"+arg) - args = append(args, sql.Named(arg, projectId)) - } - inClause := strings.Join(inClauses, ", ") - whereClause := "project_id in (" + inClause + ")" + args := []any{sql.Named("project_ids", projectIds)} + whereClause := "project_id in @project_ids" query := fmt.Sprintf(listStoresTemplate, whereClause, limit) if afterItem != nil { @@ -84,15 +75,8 @@ func (s *StoreRepository) ListRefresh(ctx context.Context, projectIds []string, return nil, time.Time{}, errors.New(ctx, errors.InvalidParameter, op, "missing limit") } - var inClauses []string - var args []any - for i, projectId := range projectIds { - arg := "project_id_" + strconv.Itoa(i) - inClauses = append(inClauses, "@"+arg) - args = append(args, sql.Named(arg, projectId)) - } - inClause := strings.Join(inClauses, ", ") - whereClause := "project_id in (" + inClause + ")" + args := []any{sql.Named("project_ids", projectIds)} + whereClause := "project_id in @project_ids" query := fmt.Sprintf(listStoresRefreshTemplate, whereClause, limit) args = append(args,