更换热重载工具为air

This commit is contained in:
2024-10-26 05:54:32 +08:00
parent 61c2840612
commit 925f1f4b3b
5 changed files with 15 additions and 91 deletions

View File

@@ -250,6 +250,7 @@ func NewSchema(config Config) (graphql.Schema, error) {
// 筛选条件
var where []string
var order []string
for arg, format := range argToSQLFormat {
if p.Args[arg] != nil {
where = append(where, fmt.Sprintf(format, p.Args[arg]))
@@ -273,7 +274,8 @@ func NewSchema(config Config) (graphql.Schema, error) {
if ids_str == "" {
return map[string]interface{}{"list": []Image{}, "total": 0}, nil
}
where = append(where, fmt.Sprintf("id IN (%s) LIMIT %d", ids_str, len(id_list)))
where = append(where, fmt.Sprintf("id IN (%s)", ids_str))
order = append(order, fmt.Sprintf("ORDER BY FIELD(id,%s)", ids_str))
}
// 特殊处理 text 参数
@@ -310,6 +312,7 @@ func NewSchema(config Config) (graphql.Schema, error) {
}
where_str := strings.Join(where, " AND ")
order_str := strings.Join(order, "")
if where_str != "" {
where_str = "WHERE " + where_str
@@ -332,23 +335,23 @@ func NewSchema(config Config) (graphql.Schema, error) {
offset = len(id_list) - limit
}
where_str += fmt.Sprintf(" LIMIT %d OFFSET %d", limit, offset)
// 执行查询
var query strings.Builder
fields := strings.Join(get_fields(p.Info.FieldASTs[0].SelectionSet.Selections), ",")
query.WriteString(fmt.Sprintf("SELECT %s FROM web_images %s", fields, where_str))
query.WriteString(fmt.Sprintf("SELECT %s FROM web_images %s %s LIMIT %d OFFSET %d", fields, where_str, order_str, limit, offset))
var images ImageList
if err := connection.Select(&images, query.String()); err != nil {
var q = query.String()
fmt.Println(q)
if err := connection.Select(&images, q); err != nil {
fmt.Println("获取图像列表失败", err)
return nil, err
}
// 按照 id_list 的顺序重新排序
if len(id_list) > 0 {
images.SortByIDList(id_list)
}
//if len(id_list) > 0 {
// images.SortByIDList(id_list)
//}
// 获取用户信息(如果图像列表不为空且请求字段中包含user)
if len(images) > 0 && strings.Contains(fields, "user") {