feat(engine): 实现内存存储自动创建集合功能

- 修改 Insert 方法支持集合不存在时自动创建
- 添加集合创建逻辑并初始化文档映射
- 保持线程安全的集合操作机制
This commit is contained in:
kingecg 2026-03-14 20:37:56 +08:00
parent 7b38ec9877
commit 3a08ac0617
1 changed files with 9 additions and 2 deletions

View File

@ -87,11 +87,18 @@ func (ms *MemoryStore) GetCollection(name string) (*Collection, error) {
return coll, nil
}
// Insert 插入文档到内存
// Insert 插入文档到内存(集合不存在时自动创建)
func (ms *MemoryStore) Insert(collection string, doc types.Document) error {
coll, err := ms.GetCollection(collection)
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()