mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 13:07:46 +00:00
feat(db): Adding identity_providers table for relational database
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user