This commit is contained in:
breel
2020-08-07 22:10:02 -06:00
parent 304956da74
commit 46bd1bbdfc
17 changed files with 599 additions and 394 deletions

View File

@@ -71,13 +71,13 @@ 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 one.ID == "" {
return errors.New("cannot create document without id")
}
if ones, err := g.ListCaseInsensitive(ctx, namespace, one.Name); err != nil {
if ones, err := g.ListCaseInsensitive(ctx, namespace, one.ID); err != nil {
return err
} else if len(ones) > 0 {
return fmt.Errorf("collision on primary key when case insensitive: cannot create %q because %+v exists", one.Name, ones)
return fmt.Errorf("collision on primary key when case insensitive: cannot create %q because %+v exists", one.ID, ones)
}
return g.driver.Insert(ctx, namespace, one)
}