Support primary key ID and unique key Name where api uses name
This commit is contained in:
@@ -106,18 +106,18 @@ func (mp *Map) Insert(_ context.Context, namespace string, doc interface{}) erro
|
||||
if err := bson.Unmarshal(b, &m); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, ok := m[entity.Name]; !ok {
|
||||
return errors.New("primary key required to insert: did not find " + entity.Name)
|
||||
} else if _, ok := m[entity.Name].(string); !ok {
|
||||
if _, ok := m[entity.ID]; !ok {
|
||||
return errors.New("primary key required to insert: did not find " + entity.ID)
|
||||
} else if _, ok := m[entity.ID].(string); !ok {
|
||||
return errors.New("primary key must be a string")
|
||||
}
|
||||
if _, ok := mp.db[namespace][m[entity.Name].(string)]; ok {
|
||||
if _, ok := mp.db[namespace][m[entity.ID].(string)]; ok {
|
||||
return errors.New("cannot insert: collision on primary key")
|
||||
}
|
||||
if _, ok := mp.db[namespace]; !ok {
|
||||
mp.db[namespace] = make(map[string][]byte)
|
||||
}
|
||||
mp.db[namespace][m[entity.Name].(string)] = b
|
||||
mp.db[namespace][m[entity.ID].(string)] = b
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user