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

Function jsonColumnExample

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

jsonColumnExample 演示 JSON 列的优势

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

Source from the content-addressed store, hash-verified

118
119// jsonColumnExample 演示 JSON 列的优势
120func jsonColumnExample(ctx context.Context, service *mysql.Service, sessionID string) {
121 // MySQL 8.0+ 的 JSON 列优势:
122 // 1. 原生 JSON 类型(不是字符串)
123 // 2. 自动验证 JSON 格式
124 // 3. 支持 JSON 函数查询
125 // 4. 可以为 JSON 字段创建虚拟列索引
126
127 event := &session.Event{
128 ID: "evt-" + generateID(),
129 Timestamp: time.Now(),
130 InvocationID: "inv-mysql-002",
131 AgentID: "agent-mysql-support",
132 Branch: "root",
133 Author: "assistant",
134 Content: types.Message{
135 Role: types.RoleAssistant,
136 Content: "MySQL 支持丰富的 JSON 操作",
137 ToolCalls: []types.ToolCall{
138 {
139 ID: "call-1",
140 Name: "json_demo",
141 Arguments: map[string]any{
142 "nested": map[string]any{
143 "level1": map[string]any{
144 "level2": "深层嵌套也可以",
145 },
146 },
147 "array": []string{"item1", "item2", "item3"},
148 },
149 },
150 },
151 },
152 Metadata: map[string]any{
153 "mysql_features": []string{
154 "JSON_EXTRACT",
155 "JSON_CONTAINS",
156 "JSON_SEARCH",
157 "Virtual Columns",
158 },
159 },
160 }
161
162 if err := service.AppendEvent(ctx, sessionID, event); err != nil {
163 log.Fatalf("Failed to append JSON example event: %v", err)
164 }
165
166 fmt.Println("✅ Complex JSON structure stored")
167 fmt.Println(" MySQL can query nested fields efficiently")
168}
169
170// queryOptimizationExample 查询优化示例
171func queryOptimizationExample(ctx context.Context, service *mysql.Service, userID string) {

Callers 1

mainFunction · 0.85

Calls 2

generateIDFunction · 0.70
AppendEventMethod · 0.65

Tested by

no test coverage detected