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

Function queryOptimizationExample

examples/session-mysql/main.go:171–193  ·  view source on GitHub ↗

queryOptimizationExample 查询优化示例

(ctx context.Context, service *mysql.Service, userID string)

Source from the content-addressed store, hash-verified

169
170// queryOptimizationExample 查询优化示例
171func queryOptimizationExample(ctx context.Context, service *mysql.Service, userID string) {
172 // 列出用户的 Sessions
173 sessions, err := service.List(ctx, userID, &session.ListOptions{
174 Limit: 10,
175 })
176 if err != nil {
177 log.Fatalf("Failed to list sessions: %v", err)
178 }
179
180 fmt.Printf("✅ Found %d sessions\n", len(sessions))
181
182 if len(sessions) > 0 {
183 // 获取事件
184 events, err := service.GetEvents(ctx, sessions[0].ID, &session.EventOptions{
185 Limit: 5,
186 })
187 if err != nil {
188 log.Fatalf("Failed to get events: %v", err)
189 }
190
191 fmt.Printf("✅ Session has %d events\n", len(events))
192 }
193}
194
195// 辅助函数
196

Callers 1

mainFunction · 0.85

Calls 3

PrintfMethod · 0.80
ListMethod · 0.65
GetEventsMethod · 0.65

Tested by

no test coverage detected