impl entities and test

This commit is contained in:
breel
2020-08-09 10:41:37 -06:00
parent 64772166cc
commit 468e5bedd5
4 changed files with 448 additions and 14 deletions

View File

@@ -310,6 +310,14 @@ func applySet(doc, operator bson.M) (bson.M, error) {
if k == entity.ID {
continue
}
if k == "." {
m, ok := v.(bson.M)
if !ok {
return nil, errors.New("cannot assign non-map to doc")
}
doc = m
return doc, nil
}
nesting := strings.Split(k, ".")
if len(nesting) > 1 {
mInterface, ok := doc[nesting[0]]

View File

@@ -74,10 +74,8 @@ func (g Graph) Insert(ctx context.Context, namespace string, one entity.One) err
if one.ID == "" {
return errors.New("cannot create document without id")
}
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.ID, ones)
if one, err := g.Get(ctx, namespace, one.ID); err == nil {
return fmt.Errorf("collision on primary key when case insensitive: cannot create %q because %+v exists", one.ID, one)
}
return g.driver.Insert(ctx, namespace, one)
}