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) {
|
func scanInstance(ctx context.Context, querier database.Querier, builder *database.StatementBuilder) (*domain.Instance, error) {
|
||||||
instance := &domain.Instance{}
|
rows, err := querier.Query(ctx, builder.String(), builder.Args()...)
|
||||||
err := scan(ctx, querier, builder, instance)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
instance := new(domain.Instance)
|
||||||
|
if err := rows.(database.CollectableRows).CollectExactlyOneRow(instance); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return instance, nil
|
return instance, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func scanInstances(ctx context.Context, querier database.Querier, builder *database.StatementBuilder) ([]*domain.Instance, error) {
|
func scanInstances(ctx context.Context, querier database.Querier, builder *database.StatementBuilder) (instances []*domain.Instance, err error) {
|
||||||
instances := []*domain.Instance{}
|
rows, err := querier.Query(ctx, builder.String(), builder.Args()...)
|
||||||
err := scanMultiple(ctx, querier, builder, &instances)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := rows.(database.CollectableRows).Collect(&instances); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return instances, nil
|
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) {
|
func scanOrganization(ctx context.Context, querier database.Querier, builder *database.StatementBuilder) (*domain.Organization, error) {
|
||||||
organization := &domain.Organization{}
|
rows, err := querier.Query(ctx, builder.String(), builder.Args()...)
|
||||||
err := scan(ctx, querier, builder, organization)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
organization := &domain.Organization{}
|
||||||
|
if err := rows.(database.CollectableRows).CollectExactlyOneRow(organization); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return organization, nil
|
return organization, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func scanOrganizations(ctx context.Context, querier database.Querier, builder *database.StatementBuilder) ([]*domain.Organization, error) {
|
func scanOrganizations(ctx context.Context, querier database.Querier, builder *database.StatementBuilder) ([]*domain.Organization, error) {
|
||||||
organizations := []*domain.Organization{}
|
rows, err := querier.Query(ctx, builder.String(), builder.Args()...)
|
||||||
err := scanMultiple(ctx, querier, builder, &organizations)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
organizations := []*domain.Organization{}
|
||||||
|
if err := rows.(database.CollectableRows).Collect(&organizations); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return organizations, nil
|
return organizations, nil
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,6 @@ package repository
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
|
|
||||||
"github.com/zitadel/zitadel/backend/v3/storage/database"
|
"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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := rows.(database.CollectableRows).CollectExactlyOneRow(res); err != nil {
|
return rows.(database.CollectableRows).CollectExactlyOneRow(res)
|
||||||
if err.Error() == "no rows in result set" {
|
|
||||||
return ErrResourceDoesNotExist
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func scanMultiple(ctx context.Context, querier database.Querier, builder *database.StatementBuilder, res any) error {
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := rows.(database.CollectableRows).Collect(res); err != nil {
|
return rows.(database.CollectableRows).Collect(res)
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user