impl entities and test
This commit is contained in:
@@ -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]]
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user