feat(engine): 实现内存存储自动创建集合功能
- 修改 Insert 方法支持集合不存在时自动创建 - 添加集合创建逻辑并初始化文档映射 - 保持线程安全的集合操作机制
This commit is contained in:
parent
7b38ec9877
commit
3a08ac0617
|
|
@ -87,11 +87,18 @@ func (ms *MemoryStore) GetCollection(name string) (*Collection, error) {
|
||||||
return coll, nil
|
return coll, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert 插入文档到内存
|
// Insert 插入文档到内存(集合不存在时自动创建)
|
||||||
func (ms *MemoryStore) Insert(collection string, doc types.Document) error {
|
func (ms *MemoryStore) Insert(collection string, doc types.Document) error {
|
||||||
coll, err := ms.GetCollection(collection)
|
coll, err := ms.GetCollection(collection)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
// 集合不存在则创建
|
||||||
|
ms.mu.Lock()
|
||||||
|
ms.collections[collection] = &Collection{
|
||||||
|
name: collection,
|
||||||
|
documents: make(map[string]types.Document),
|
||||||
|
}
|
||||||
|
coll = ms.collections[collection]
|
||||||
|
ms.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
coll.mu.Lock()
|
coll.mu.Lock()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue