feat 奇怪的知识1.0.1

This commit is contained in:
2026-01-13 11:27:57 +08:00
parent 7ff0234ca6
commit 47b89b6746
10 changed files with 535 additions and 29 deletions

View File

@@ -18,6 +18,7 @@ import (
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
return &Query{
db: db,
Category: newCategory(db, opts...),
Question: newQuestion(db, opts...),
}
}
@@ -25,6 +26,7 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
type Query struct {
db *gorm.DB
Category category
Question question
}
@@ -33,6 +35,7 @@ func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query {
return &Query{
db: db,
Category: q.Category.clone(db),
Question: q.Question.clone(db),
}
}
@@ -48,16 +51,19 @@ func (q *Query) WriteDB() *Query {
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
return &Query{
db: db,
Category: q.Category.replaceDB(db),
Question: q.Question.replaceDB(db),
}
}
type queryCtx struct {
Category *categoryDo
Question *questionDo
}
func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{
Category: q.Category.WithContext(ctx),
Question: q.Question.WithContext(ctx),
}
}