From 3a08ac0617c2fd4f52c41dc8e7843c2135b730d9 Mon Sep 17 00:00:00 2001 From: kingecg Date: Sat, 14 Mar 2026 20:37:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(engine):=20=E5=AE=9E=E7=8E=B0=E5=86=85?= =?UTF-8?q?=E5=AD=98=E5=AD=98=E5=82=A8=E8=87=AA=E5=8A=A8=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E9=9B=86=E5=90=88=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 Insert 方法支持集合不存在时自动创建 - 添加集合创建逻辑并初始化文档映射 - 保持线程安全的集合操作机制 --- internal/engine/memory_store.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/engine/memory_store.go b/internal/engine/memory_store.go index bcac28e..721483f 100644 --- a/internal/engine/memory_store.go +++ b/internal/engine/memory_store.go @@ -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()