MCPcopy Create free account
hub / github.com/53AI/53AIHub / Save

Method Save

api/model/library.go:58–83  ·  view source on GitHub ↗

Save 创建知识库

()

Source from the content-addressed store, hash-verified

56
57// Save 创建知识库
58func (library *Library) Save() error {
59 if library.Name == "" {
60 return errors.New("library name is required")
61 }
62 if library.LibraryKind == "" {
63 library.LibraryKind = LIBRARY_KIND_REGULAR
64 }
65
66 // 检查同一空间下知识库名称是否重复
67 existingLibrary, err := GetLibraryByName(library.SpaceID, library.Name)
68 if err == nil && existingLibrary != nil {
69 return errors.New("library name already exists in this space")
70 }
71
72 // 生成UUID
73 if library.UUID == "" {
74 library.UUID = uuid.New().String()
75 }
76
77 result := DB.Create(library)
78 if result.Error != nil {
79 return result.Error
80 }
81 invalidateLibraryCache(library.Eid)
82 return nil
83}
84
85// SaveWithTx 使用传入事务创建知识库(避免全局DB依赖)
86func (library *Library) SaveWithTx(tx *gorm.DB) error {

Callers 4

CreateLibraryMethod · 0.95
migrateEnterpriseDataFunction · 0.95
CreateDefaultLibraryFunction · 0.95

Calls 5

GetLibraryByNameFunction · 0.85
invalidateLibraryCacheFunction · 0.70
NewMethod · 0.45
StringMethod · 0.45
CreateMethod · 0.45

Tested by

no test coverage detected