This commit is contained in:
oneao committed 2026-04-16 21:29:38 +08:00
1 parent 6300778150
commit e893ef2e48
27 files changed
+870 -33

No files matched your search

+17 -7
View File
@@ -13,7 +13,7 @@ func (c *Client) LoadData(
orderBy string,
searchColumns []string,
args []any,
) ([][]any, error) {
) ([]map[string]any, error) {
var where string
@@ -50,12 +50,14 @@ func (c *Client) LoadDataBySQL(
ctx context.Context,
sql string,
args []any,
) ([][]any, error) {
) ([]map[string]any, error) {
return c.query(ctx, sql, args...)
}
// 统一查询方法(核心优化)
func (c *Client) query(ctx context.Context, sql string, args ...any) ([][]any, error) {
// ==========================
// 核心查询方法(已升级)
// ==========================
func (c *Client) query(ctx context.Context, sql string, args ...any) ([]map[string]any, error) {
sql = convertPlaceholder(sql)
rows, err := c.exec().Query(ctx, sql, args...)
@@ -64,7 +66,10 @@ func (c *Client) query(ctx context.Context, sql string, args ...any) ([][]any, e
}
defer rows.Close()
result := make([][]any, 0, 16)
// 获取字段名
fields := rows.FieldDescriptions()
result := make([]map[string]any, 0, 16)
for rows.Next() {
values, err := rows.Values()
@@ -72,8 +77,13 @@ func (c *Client) query(ctx context.Context, sql string, args ...any) ([][]any, e
return nil, err
}
row := make([]any, len(values))
copy(row, values)
row := make(map[string]any, len(values))
for i, f := range fields {
if i < len(values) {
row[string(f.Name)] = values[i]
}
}
result = append(result, row)
}