MCPcopy Create free account
hub / github.com/astercloud/aster / List

Method List

pkg/memory/logic/store_mysql.go:225–298  ·  view source on GitHub ↗

List 列出符合条件的 Memory

(ctx context.Context, namespace string, filters ...Filter)

Source from the content-addressed store, hash-verified

223
224// List 列出符合条件的 Memory
225func (s *MySQLStore) List(ctx context.Context, namespace string, filters ...Filter) ([]*LogicMemory, error) {
226 if s.closed {
227 return nil, ErrStoreClosed
228 }
229
230 opts := ApplyFilters(filters...)
231
232 // 构建查询
233 query := fmt.Sprintf(`
234 SELECT id, namespace, scope, type, category, `+"`key`"+`, value, description,
235 source_type, confidence, sources, provenance_created_at, provenance_updated_at, provenance_version,
236 access_count, last_accessed, metadata, created_at, updated_at
237 FROM %s
238 WHERE 1=1
239 `, s.tableName)
240
241 args := []any{}
242
243 if namespace != "" {
244 query += " AND namespace = ?"
245 args = append(args, namespace)
246 }
247
248 if opts.Type != "" {
249 query += " AND type = ?"
250 args = append(args, opts.Type)
251 }
252
253 if opts.Scope != "" {
254 query += " AND scope = ?"
255 args = append(args, opts.Scope)
256 }
257
258 if opts.MinConfidence > 0 {
259 query += " AND confidence >= ?"
260 args = append(args, opts.MinConfidence)
261 }
262
263 // 排序
264 switch opts.OrderBy {
265 case OrderByConfidence:
266 query += " ORDER BY confidence DESC"
267 case OrderByLastAccessed:
268 query += " ORDER BY last_accessed DESC"
269 case OrderByCreatedAt:
270 query += " ORDER BY created_at DESC"
271 case OrderByAccessCount:
272 query += " ORDER BY access_count DESC"
273 default:
274 query += " ORDER BY confidence DESC"
275 }
276
277 // 限制数量
278 if opts.MaxResults > 0 {
279 query += fmt.Sprintf(" LIMIT %d", opts.MaxResults)
280 }
281
282 rows, err := s.db.QueryContext(ctx, query, args...)

Callers 3

SearchByTypeMethod · 0.95
SearchByScopeMethod · 0.95
GetTopKMethod · 0.95

Calls 4

scanMemoryFromRowsMethod · 0.95
ApplyFiltersFunction · 0.85
NewStoreErrorFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected