Skip to content

Commit ba8311e

Browse files
authored
feat: Add unified Execute interface design in client_design.md (#165)
* feat: Add unified Execute interface design in client_design.md (#164) Signed-off-by: mikkeyf <1647228132@qq.com> * feat: Add unified Execute interface design in client_design.md Signed-off-by: mikkeyf <1647228132@qq.com> * feat: Add unified Execute interface design in client_design.md - Add comprehensive Execute interface with automatic statement routing - Support parameterized queries with type safety - Add OpenTelemetry integration design with interceptor pattern - Fix mermaid syntax errors in all diagrams (added missing classDiagram declarations) - Fix both English and Chinese versions This provides a cleaner unified API for SQL-like operations while maintaining backward compatibility with existing methods. Signed-off-by: mikkeyf <1647228132@qq.com> * feat: Add unified Execute interface design in client_design.md - Add comprehensive Execute interface with automatic statement routing - Support parameterized queries with type safety - Add OpenTelemetry integration design with interceptor pattern - Fix mermaid syntax errors in all diagrams (added missing classDiagram declarations) - Fix both English and Chinese versions This provides a cleaner unified API for SQL-like operations while maintaining backward compatibility with existing methods. Signed-off-by: mikkeyf <1647228132@qq.com> --------- Signed-off-by: mikkeyf <1647228132@qq.com>
1 parent 526f8b7 commit ba8311e

3 files changed

Lines changed: 278 additions & 23 deletions

File tree

openGemini.github.io

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/guide/develop/client_design.md

Lines changed: 139 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,128 @@ classDiagram
198198
BatchPoints "1" *-- "many" Point: contains
199199
```
200200

201+
# Execute interface design
202+
203+
The Execute interface provides a unified SQL execution interface that automatically routes different types of statements to appropriate underlying methods. This design supports SQL-like statements including INSERT, SELECT, CREATE, DROP, and other database operations with parameter support and type safety.
204+
205+
```mermaid
206+
classDiagram
207+
class OpenGeminiClient {
208+
+ ExecuteResult Execute(Statement statement)
209+
+ ExecuteResult ExecuteContext(Context ctx, Statement statement)
210+
}
211+
212+
class Statement {
213+
+ String database
214+
+ String command
215+
+ Map~String, Object~ params
216+
+ String retentionPolicy
217+
}
218+
219+
class ExecuteResult {
220+
+ QueryResult queryResult
221+
+ int64 affectedRows
222+
+ StatementType statementType
223+
+ Error error
224+
}
225+
226+
class StatementType {
227+
<<enum>>
228+
StatementTypeUnknown
229+
StatementTypeQuery // SELECT, SHOW, EXPLAIN → routed to Query()
230+
StatementTypeCommand // CREATE, DROP, ALTER → routed to Query()
231+
StatementTypeInsert // INSERT → routed to Write methods
232+
+ String() String
233+
+ IsQueryLike() bool
234+
+ IsWriteLike() bool
235+
}
236+
237+
OpenGeminiClient --> Statement : uses
238+
OpenGeminiClient --> ExecuteResult : returns
239+
ExecuteResult --> StatementType : contains
240+
ExecuteResult --> QueryResult : contains
241+
```
242+
243+
## Statement routing logic
244+
245+
```mermaid
246+
flowchart TD
247+
A[Execute Statement] --> B{Parse Statement Type}
248+
B -->|SELECT, SHOW, EXPLAIN, DESCRIBE, WITH| C[StatementTypeQuery]
249+
B -->|CREATE, DROP, ALTER, UPDATE, DELETE| D[StatementTypeCommand]
250+
B -->|INSERT| E[StatementTypeInsert]
251+
B -->|Other| F[StatementTypeUnknown]
252+
253+
C --> G[Route to Query method]
254+
D --> G[Route to Query method]
255+
E --> H[Route to Write methods]
256+
F --> I[Return error]
257+
258+
G --> J[Return QueryResult + AffectedRows=0/1]
259+
H --> K[Return AffectedRows=point count]
260+
I --> L[Return error result]
261+
```
262+
263+
## Parameter support
264+
265+
The Execute interface supports parameterized statements with automatic type conversion:
266+
267+
```mermaid
268+
classDiagram
269+
class ParameterTypes {
270+
<<enum>>
271+
String // "value" → value
272+
Integer // 42 → 42i
273+
UInteger // 42 → 42u
274+
Float // 3.14 → 3.14
275+
Boolean // true → true
276+
}
277+
278+
class ParameterProcessor {
279+
+ replaceParams(command String, params Map) String
280+
+ convertParamValue(value Object) String
281+
+ validateParams(command String, params Map) Error
282+
}
283+
284+
Statement --> ParameterProcessor : uses
285+
ParameterProcessor --> ParameterTypes : converts
286+
```
287+
288+
## Usage examples
289+
290+
### Basic usage
291+
```go
292+
result, err := client.Execute(opengemini.Statement{
293+
Database: "mydb",
294+
Command: "SELECT * FROM weather LIMIT 10",
295+
})
296+
```
297+
298+
### Parameterized query
299+
```go
300+
result, err := client.Execute(opengemini.Statement{
301+
Database: "mydb",
302+
Command: "SELECT * FROM weather WHERE location=$loc AND temp>$temp",
303+
Params: map[string]any{
304+
"loc": "beijing",
305+
"temp": 25.0,
306+
},
307+
})
308+
```
309+
310+
### Parameterized insert
311+
```go
312+
result, err := client.Execute(opengemini.Statement{
313+
Database: "mydb",
314+
Command: "INSERT weather,location=$location temperature=$temp,humidity=$hum",
315+
Params: map[string]any{
316+
"location": "shanghai",
317+
"temp": 30.2,
318+
"hum": 70,
319+
},
320+
})
321+
```
322+
201323
# Query design
202324

203325
```mermaid
@@ -253,33 +375,39 @@ The interceptor pattern defines a standardized interface to hook into client ope
253375

254376

255377
```mermaid
256-
Interceptor interface {
257-
Query(ctx context.Context, query *InterceptorQuery) InterceptorClosure
258-
Write(ctx context.Context, write *InterceptorWrite) InterceptorClosure
259-
}
378+
classDiagram
379+
class Interceptor {
380+
<<interface>>
381+
+ Query(ctx context.Context, query *InterceptorQuery) InterceptorClosure
382+
+ Write(ctx context.Context, write *InterceptorWrite) InterceptorClosure
383+
}
260384
```
261385

262386
## Define the base client class,associated with the Interceptor interface
263387
The base  Client  class manages a collection of interceptors, allowing dynamic registration and execution of interceptor logic during client operations.
264388

265389
```mermaid
266-
class Client {
267-
- []Interceptor interceptors
268-
}
390+
classDiagram
391+
class Client {
392+
- interceptors: List~Interceptor~
393+
}
269394
```
270395

271396
## Define the interceptor implementation class integrating OpenTelemetry,implementing the Interceptor interface
272397
The OtelClient class implements the Interceptor interface, embedding OpenTelemetry logic to capture traces, metrics, and logs for client operations.
273398

274399
```mermaid
275-
class OtelClient {
276-
Interceptor
277-
}
400+
classDiagram
401+
class OtelClient {
402+
<<implements Interceptor>>
403+
}
404+
OtelClient ..|> Interceptor : implements
278405
```
279406

280407
## Tracing system core module
281408

282409
```mermaid
410+
classDiagram
283411
class TraceContext {
284412
+ traceId: String
285413
+ parentTraceId: String
@@ -387,7 +515,7 @@ class OtelClient {
387515

388516
## Usage Example(Go language examples)
389517

390-
```mermaid
518+
```go
391519
func main() {
392520
var ctx = context.Background()
393521
shutdown, err := setupOtelSDK(ctx)

src/zh/guide/develop/client_design.md

Lines changed: 139 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,128 @@ classDiagram
199199
BatchPoints "1" *-- "many" Point: contains
200200
```
201201

202+
# Execute 接口设计
203+
204+
Execute 接口提供了一个统一的 SQL 执行接口,可以自动将不同类型的语句路由到相应的底层方法。该设计支持类 SQL 语句,包括 INSERT、SELECT、CREATE、DROP 和其他数据库操作,并提供参数支持和类型安全。
205+
206+
```mermaid
207+
classDiagram
208+
class OpenGeminiClient {
209+
+ ExecuteResult Execute(Statement statement)
210+
+ ExecuteResult ExecuteContext(Context ctx, Statement statement)
211+
}
212+
213+
class Statement {
214+
+ String database
215+
+ String command
216+
+ Map~String, Object~ params
217+
+ String retentionPolicy
218+
}
219+
220+
class ExecuteResult {
221+
+ QueryResult queryResult
222+
+ int64 affectedRows
223+
+ StatementType statementType
224+
+ Error error
225+
}
226+
227+
class StatementType {
228+
<<enum>>
229+
StatementTypeUnknown
230+
StatementTypeQuery // SELECT, SHOW, EXPLAIN → 路由到 Query()
231+
StatementTypeCommand // CREATE, DROP, ALTER → 路由到 Query()
232+
StatementTypeInsert // INSERT → 路由到 Write 方法
233+
+ String() String
234+
+ IsQueryLike() bool
235+
+ IsWriteLike() bool
236+
}
237+
238+
OpenGeminiClient --> Statement : 使用
239+
OpenGeminiClient --> ExecuteResult : 返回
240+
ExecuteResult --> StatementType : 包含
241+
ExecuteResult --> QueryResult : 包含
242+
```
243+
244+
## 语句路由逻辑
245+
246+
```mermaid
247+
flowchart TD
248+
A[执行语句] --> B{解析语句类型}
249+
B -->|SELECT, SHOW, EXPLAIN, DESCRIBE, WITH| C[StatementTypeQuery]
250+
B -->|CREATE, DROP, ALTER, UPDATE, DELETE| D[StatementTypeCommand]
251+
B -->|INSERT| E[StatementTypeInsert]
252+
B -->|其他| F[StatementTypeUnknown]
253+
254+
C --> G[路由到 Query 方法]
255+
D --> G[路由到 Query 方法]
256+
E --> H[路由到 Write 方法]
257+
F --> I[返回错误]
258+
259+
G --> J[返回 QueryResult + AffectedRows=0/1]
260+
H --> K[返回 AffectedRows=数据点数量]
261+
I --> L[返回错误结果]
262+
```
263+
264+
## 参数支持
265+
266+
Execute 接口支持参数化语句并自动进行类型转换:
267+
268+
```mermaid
269+
classDiagram
270+
class ParameterTypes {
271+
<<enum>>
272+
String // "value" → value
273+
Integer // 42 → 42i
274+
UInteger // 42 → 42u
275+
Float // 3.14 → 3.14
276+
Boolean // true → true
277+
}
278+
279+
class ParameterProcessor {
280+
+ replaceParams(command String, params Map) String
281+
+ convertParamValue(value Object) String
282+
+ validateParams(command String, params Map) Error
283+
}
284+
285+
Statement --> ParameterProcessor : 使用
286+
ParameterProcessor --> ParameterTypes : 转换
287+
```
288+
289+
## 使用示例
290+
291+
### 基本用法
292+
```go
293+
result, err := client.Execute(opengemini.Statement{
294+
Database: "mydb",
295+
Command: "SELECT * FROM weather LIMIT 10",
296+
})
297+
```
298+
299+
### 参数化查询
300+
```go
301+
result, err := client.Execute(opengemini.Statement{
302+
Database: "mydb",
303+
Command: "SELECT * FROM weather WHERE location=$loc AND temp>$temp",
304+
Params: map[string]any{
305+
"loc": "beijing",
306+
"temp": 25.0,
307+
},
308+
})
309+
```
310+
311+
### 参数化插入
312+
```go
313+
result, err := client.Execute(opengemini.Statement{
314+
Database: "mydb",
315+
Command: "INSERT weather,location=$location temperature=$temp,humidity=$hum",
316+
Params: map[string]any{
317+
"location": "shanghai",
318+
"temp": 30.2,
319+
"hum": 70,
320+
},
321+
})
322+
```
323+
202324
# 查询设计
203325

204326
```mermaid
@@ -236,33 +358,39 @@ classDiagram
236358
拦截器模式定义了标准化接口,用于挂钩客户端操作(查询/写入)并注入遥测逻辑。
237359

238360
```mermaid
239-
Interceptor interface {
240-
Query(ctx context.Context, query *InterceptorQuery) InterceptorClosure
241-
Write(ctx context.Context, write *InterceptorWrite) InterceptorClosure
242-
}
361+
classDiagram
362+
class Interceptor {
363+
<<interface>>
364+
+ Query(ctx context.Context, query *InterceptorQuery) InterceptorClosure
365+
+ Write(ctx context.Context, write *InterceptorWrite) InterceptorClosure
366+
}
243367
```
244368

245369
## 定义基础客户端类,关联拦截器接口
246370
基础 Client 类管理一组拦截器,允许在客户端操作期间动态注册和执行拦截器逻辑。
247371

248372
```mermaid
249-
class Client {
250-
- []Interceptor interceptors
251-
}
373+
classDiagram
374+
class Client {
375+
- interceptors: List~Interceptor~
376+
}
252377
```
253378

254379
## 定义集成 OpenTelemetry 的拦截器实现类,实现 Interceptor 接口
255380
OtelClient 类实现 Interceptor 接口,嵌入 OpenTelemetry 逻辑以捕获客户端操作的跟踪、指标和日志。
256381

257382
```mermaid
258-
class OtelClient {
259-
Interceptor
260-
}
383+
classDiagram
384+
class OtelClient {
385+
<<implements Interceptor>>
386+
}
387+
OtelClient ..|> Interceptor : implements
261388
```
262389

263390
## 追踪系统核心模块
264391

265392
```mermaid
393+
classDiagram
266394
class TraceContext {
267395
+ traceId: String
268396
+ parentTraceId: String
@@ -370,7 +498,7 @@ class OtelClient {
370498

371499
## 使用示例(Go language examples)
372500

373-
```mermaid
501+
```go
374502
func main() {
375503
var ctx = context.Background()
376504
shutdown, err := setupOtelSDK(ctx)

0 commit comments

Comments
 (0)