Support primary key ID and unique key Name where api uses name

This commit is contained in:
breel
2020-08-02 09:59:47 -06:00
parent 37fe9415e7
commit 8e6e86955e
14 changed files with 68 additions and 49 deletions

View File

@@ -2,6 +2,7 @@ package storage
import (
"context"
"errors"
"fmt"
"local/dndex/storage/driver"
"local/dndex/storage/entity"
@@ -56,6 +57,9 @@ func (g Graph) gatherOnes(ctx context.Context, ch <-chan bson.Raw) ([]entity.One
}
func (g Graph) Insert(ctx context.Context, namespace string, one entity.One) error {
if one.Name == "" || one.ID == "" {
return errors.New("cannot create document without both name and id")
}
if ones, err := g.ListCaseInsensitive(ctx, namespace, one.Name); err != nil {
return err
} else if len(ones) > 0 {