fix(extensions): 修复插件最新版查询

This commit is contained in:
yokowu
2025-07-09 11:18:28 +08:00
parent 550d4015c4
commit dfd3d88f9b

View File

@@ -2,6 +2,7 @@ package repo
import (
"context"
"fmt"
"entgo.io/ent/dialect/sql"
@@ -22,11 +23,18 @@ func NewExtensionRepo(db *db.Client) domain.ExtensionRepo {
// Latest implements domain.ExtensionRepo.
func (e *ExtensionRepo) Latest(ctx context.Context) (*db.Extension, error) {
return e.db.Extension.
es, err := e.db.Extension.
Query().
Order(extension.ByCreatedAt(sql.OrderDesc())).
Limit(1).
Only(ctx)
All(ctx)
if err != nil {
return nil, err
}
if len(es) == 0 {
return nil, fmt.Errorf("extension not found")
}
return es[0], nil
}
// Save implements domain.ExtensionRepo.