diff --git a/backend/v3/storage/database/repository/instance.go b/backend/v3/storage/database/repository/instance.go index 0df054af63..63f878574c 100644 --- a/backend/v3/storage/database/repository/instance.go +++ b/backend/v3/storage/database/repository/instance.go @@ -172,19 +172,28 @@ func (instance) UpdatedAtColumn() database.Column { } func scanInstance(ctx context.Context, querier database.Querier, builder *database.StatementBuilder) (*domain.Instance, error) { - instance := &domain.Instance{} - err := scan(ctx, querier, builder, instance) + rows, err := querier.Query(ctx, builder.String(), builder.Args()...) if err != nil { return nil, err } + + instance := new(domain.Instance) + if err := rows.(database.CollectableRows).CollectExactlyOneRow(instance); err != nil { + return nil, err + } + return instance, nil } -func scanInstances(ctx context.Context, querier database.Querier, builder *database.StatementBuilder) ([]*domain.Instance, error) { - instances := []*domain.Instance{} - err := scanMultiple(ctx, querier, builder, &instances) +func scanInstances(ctx context.Context, querier database.Querier, builder *database.StatementBuilder) (instances []*domain.Instance, err error) { + rows, err := querier.Query(ctx, builder.String(), builder.Args()...) if err != nil { return nil, err } + + if err := rows.(database.CollectableRows).Collect(&instances); err != nil { + return nil, err + } + return instances, nil } diff --git a/backend/v3/storage/database/repository/org.go b/backend/v3/storage/database/repository/org.go index 050450932e..e8053aadd9 100644 --- a/backend/v3/storage/database/repository/org.go +++ b/backend/v3/storage/database/repository/org.go @@ -217,19 +217,28 @@ func (org) UpdatedAtColumn() database.Column { } func scanOrganization(ctx context.Context, querier database.Querier, builder *database.StatementBuilder) (*domain.Organization, error) { - organization := &domain.Organization{} - err := scan(ctx, querier, builder, organization) + rows, err := querier.Query(ctx, builder.String(), builder.Args()...) if err != nil { return nil, err } + + organization := &domain.Organization{} + if err := rows.(database.CollectableRows).CollectExactlyOneRow(organization); err != nil { + return nil, err + } + return organization, nil } func scanOrganizations(ctx context.Context, querier database.Querier, builder *database.StatementBuilder) ([]*domain.Organization, error) { - organizations := []*domain.Organization{} - err := scanMultiple(ctx, querier, builder, &organizations) + rows, err := querier.Query(ctx, builder.String(), builder.Args()...) if err != nil { return nil, err } + + organizations := []*domain.Organization{} + if err := rows.(database.CollectableRows).Collect(&organizations); err != nil { + return nil, err + } return organizations, nil } diff --git a/backend/v3/storage/database/repository/repository.go b/backend/v3/storage/database/repository/repository.go index 4a8343a0cf..f7293c816e 100644 --- a/backend/v3/storage/database/repository/repository.go +++ b/backend/v3/storage/database/repository/repository.go @@ -2,7 +2,6 @@ package repository import ( "context" - "errors" "github.com/zitadel/zitadel/backend/v3/storage/database" ) @@ -28,13 +27,7 @@ func scan(ctx context.Context, querier database.Querier, builder *database.State return err } - if err := rows.(database.CollectableRows).CollectExactlyOneRow(res); err != nil { - if err.Error() == "no rows in result set" { - return ErrResourceDoesNotExist - } - return err - } - return nil + return rows.(database.CollectableRows).CollectExactlyOneRow(res) } func scanMultiple(ctx context.Context, querier database.Querier, builder *database.StatementBuilder, res any) error { @@ -43,14 +36,5 @@ func scanMultiple(ctx context.Context, querier database.Querier, builder *databa return err } - if err := rows.(database.CollectableRows).Collect(res); err != nil { - // if no results returned, this is not a error - // it just means the organization was not found - // the caller should check if the returned organization is nil - if err.Error() == "no rows in result set" { - return nil - } - return err - } - return nil + return rows.(database.CollectableRows).Collect(res) }