Help us shape the future of Go! Take the 2026 Go Developer Survey

chapter

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chapter

type Chapter struct {
	ID            int64     `gorm:"column:id;primaryKey;autoIncrement"                                    json:"id"`
	NovelID       int64     `gorm:"column:novel_id;not null;uniqueIndex:uk_novel_chapter;index"           json:"novel_id"`
	ChapterNumber int       `gorm:"column:chapter_number;not null;uniqueIndex:uk_novel_chapter"           json:"chapter_number"`
	Title         string    `gorm:"column:title"                                                          json:"title"`
	Summary       string    `gorm:"column:summary"                                                        json:"summary"` // AI 生成的章节简介
	WordCount     int       `gorm:"column:word_count;default:0"                                           json:"word_count"`
	CreatedAt     time.Time `gorm:"column:created_at;autoCreateTime"                                      json:"created_at"`
	UpdatedAt     time.Time `gorm:"column:updated_at;autoUpdateTime"                                      json:"updated_at"`
	FilePath      string    `gorm:"-"                                                                       json:"file_path"` // 不存 DB,由 git.ChapterPath 计算
}

Chapter 是章节元数据,正文和大纲以文件形式存储在 Git 仓库中。 DB 仅保存索引和统计信息,不存实际内容。

func (Chapter) TableName

func (Chapter) TableName() string

TableName 指定 GORM 表名。

type ListByNovelOptions

type ListByNovelOptions struct {
	PageParams storage.PageParams
	Order      string // "asc"(默认) 或 "desc",按 chapter_number 排序
}

ListByNovelOptions 是 ListByNovel 的可选参数。零值即可直接使用(默认升序)。

type Store

type Store struct {
	DB *gorm.DB
	// contains filtered or unexported fields
}

Store 管理 Chapter 持久化。DB 导出供调用方做简单 CRUD。

func NewStore

func NewStore(db *gorm.DB, logger *slog.Logger) *Store

NewStore 创建 chapter 存储。

func (*Store) GetByNovelAndNumber

func (s *Store) GetByNovelAndNumber(ctx context.Context, novelID int64, chapterNumber int) (*Chapter, error)

GetByNovelAndNumber 按 novel_id + chapter_number 取单章。

func (*Store) GetLatestNumber

func (s *Store) GetLatestNumber(ctx context.Context, novelID int64) (int, error)

GetLatestNumber 返回该小说当前最大的章节编号,无章节时返回 0。

func (*Store) GetRecent

func (s *Store) GetRecent(ctx context.Context, novelID int64, limit int) ([]Chapter, error)

GetRecent 取最近 N 章,按 chapter_number 降序。

func (*Store) ListAllByNovel

func (s *Store) ListAllByNovel(ctx context.Context, novelID int64) ([]Chapter, error)

ListAllByNovel 返回某小说的全部章节(不分页),按 chapter_number 升序。

func (*Store) ListByNovel

func (s *Store) ListByNovel(ctx context.Context, novelID int64, opts ListByNovelOptions) (*storage.PageResult[Chapter], error)

ListByNovel 分页列出某小说的章节。

func (*Store) SearchByNovel

func (s *Store) SearchByNovel(ctx context.Context, novelID int64, query string, limit int) ([]Chapter, error)

SearchByNovel 按关键词搜索某小说的章节,匹配标题和摘要。

func (*Store) UpdateTitle

func (s *Store) UpdateTitle(ctx context.Context, novelID int64, chapterNumber int, title string) error

UpdateTitle 更新章节标题。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL