wip(lyra): 补充链接模型并注入分类缓存依赖

This commit is contained in:
2026-10-20 16:47:22 +08:00
parent cd0e13325f
commit bef30be3fe
4 changed files with 45 additions and 5 deletions
+6 -3
View File
@@ -3,6 +3,7 @@ package model
import (
"context"
"fmt"
"lyra/internal/cache"
sq "github.com/Masterminds/squirrel"
"github.com/jmoiron/sqlx"
@@ -19,13 +20,15 @@ type CategoryModel interface {
FindAll(ctx context.Context) ([]*Category, error)
}
type defaultCategoryModel struct {
db *sqlx.DB
db *sqlx.DB
cache *cache.Cache
}
func NewCategoryModel(db *sqlx.DB) CategoryModel {
return &defaultCategoryModel{db: db}
func NewCategoryModel(db *sqlx.DB, cache *cache.Cache) CategoryModel {
return &defaultCategoryModel{db: db, cache: cache}
}
func (m *defaultCategoryModel) FindAll(ctx context.Context) ([]*Category, error) {
query, args, err := sq.
Select("id", "slug", "title", "sort").
From("public.categories").