|
|
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
|
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
|
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
|
|
|
|
package dao
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
|
|
|
"gorm.io/gorm"
|
|
|
"gorm.io/gorm/clause"
|
|
|
"gorm.io/gorm/schema"
|
|
|
|
|
|
"gorm.io/gen"
|
|
|
"gorm.io/gen/field"
|
|
|
|
|
|
"gorm.io/plugin/dbresolver"
|
|
|
|
|
|
"joybuywork/internal/repository/model"
|
|
|
)
|
|
|
|
|
|
func newLibraryQaOption(db *gorm.DB, opts ...gen.DOOption) libraryQaOption {
|
|
|
_libraryQaOption := libraryQaOption{}
|
|
|
|
|
|
_libraryQaOption.libraryQaOptionDo.UseDB(db, opts...)
|
|
|
_libraryQaOption.libraryQaOptionDo.UseModel(&model.LibraryQaOption{})
|
|
|
|
|
|
tableName := _libraryQaOption.libraryQaOptionDo.TableName()
|
|
|
_libraryQaOption.ALL = field.NewAsterisk(tableName)
|
|
|
_libraryQaOption.ID = field.NewInt64(tableName, "id")
|
|
|
_libraryQaOption.CreatedAt = field.NewInt64(tableName, "created_at")
|
|
|
_libraryQaOption.UpdatedAt = field.NewInt64(tableName, "updated_at")
|
|
|
_libraryQaOption.IsDel = field.NewInt8(tableName, "is_del")
|
|
|
_libraryQaOption.QaID = field.NewInt64(tableName, "qa_id")
|
|
|
_libraryQaOption.Title = field.NewString(tableName, "title")
|
|
|
_libraryQaOption.ImgURL = field.NewString(tableName, "img_url")
|
|
|
_libraryQaOption.IsRight = field.NewInt8(tableName, "is_right")
|
|
|
|
|
|
_libraryQaOption.fillFieldMap()
|
|
|
|
|
|
return _libraryQaOption
|
|
|
}
|
|
|
|
|
|
type libraryQaOption struct {
|
|
|
libraryQaOptionDo libraryQaOptionDo
|
|
|
|
|
|
ALL field.Asterisk
|
|
|
ID field.Int64
|
|
|
CreatedAt field.Int64
|
|
|
UpdatedAt field.Int64
|
|
|
IsDel field.Int8 // 是否已删除(1-是,0-否)
|
|
|
QaID field.Int64 // 问题id(libary_qa表)
|
|
|
Title field.String // 答案
|
|
|
ImgURL field.String // 图片地址
|
|
|
IsRight field.Int8 // 是否正确答案
|
|
|
|
|
|
fieldMap map[string]field.Expr
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOption) Table(newTableName string) *libraryQaOption {
|
|
|
l.libraryQaOptionDo.UseTable(newTableName)
|
|
|
return l.updateTableName(newTableName)
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOption) As(alias string) *libraryQaOption {
|
|
|
l.libraryQaOptionDo.DO = *(l.libraryQaOptionDo.As(alias).(*gen.DO))
|
|
|
return l.updateTableName(alias)
|
|
|
}
|
|
|
|
|
|
func (l *libraryQaOption) updateTableName(table string) *libraryQaOption {
|
|
|
l.ALL = field.NewAsterisk(table)
|
|
|
l.ID = field.NewInt64(table, "id")
|
|
|
l.CreatedAt = field.NewInt64(table, "created_at")
|
|
|
l.UpdatedAt = field.NewInt64(table, "updated_at")
|
|
|
l.IsDel = field.NewInt8(table, "is_del")
|
|
|
l.QaID = field.NewInt64(table, "qa_id")
|
|
|
l.Title = field.NewString(table, "title")
|
|
|
l.ImgURL = field.NewString(table, "img_url")
|
|
|
l.IsRight = field.NewInt8(table, "is_right")
|
|
|
|
|
|
l.fillFieldMap()
|
|
|
|
|
|
return l
|
|
|
}
|
|
|
|
|
|
func (l *libraryQaOption) WithContext(ctx context.Context) *libraryQaOptionDo {
|
|
|
return l.libraryQaOptionDo.WithContext(ctx)
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOption) TableName() string { return l.libraryQaOptionDo.TableName() }
|
|
|
|
|
|
func (l libraryQaOption) Alias() string { return l.libraryQaOptionDo.Alias() }
|
|
|
|
|
|
func (l *libraryQaOption) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
|
|
_f, ok := l.fieldMap[fieldName]
|
|
|
if !ok || _f == nil {
|
|
|
return nil, false
|
|
|
}
|
|
|
_oe, ok := _f.(field.OrderExpr)
|
|
|
return _oe, ok
|
|
|
}
|
|
|
|
|
|
func (l *libraryQaOption) fillFieldMap() {
|
|
|
l.fieldMap = make(map[string]field.Expr, 8)
|
|
|
l.fieldMap["id"] = l.ID
|
|
|
l.fieldMap["created_at"] = l.CreatedAt
|
|
|
l.fieldMap["updated_at"] = l.UpdatedAt
|
|
|
l.fieldMap["is_del"] = l.IsDel
|
|
|
l.fieldMap["qa_id"] = l.QaID
|
|
|
l.fieldMap["title"] = l.Title
|
|
|
l.fieldMap["img_url"] = l.ImgURL
|
|
|
l.fieldMap["is_right"] = l.IsRight
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOption) clone(db *gorm.DB) libraryQaOption {
|
|
|
l.libraryQaOptionDo.ReplaceConnPool(db.Statement.ConnPool)
|
|
|
return l
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOption) replaceDB(db *gorm.DB) libraryQaOption {
|
|
|
l.libraryQaOptionDo.ReplaceDB(db)
|
|
|
return l
|
|
|
}
|
|
|
|
|
|
type libraryQaOptionDo struct{ gen.DO }
|
|
|
|
|
|
func (l libraryQaOptionDo) Debug() *libraryQaOptionDo {
|
|
|
return l.withDO(l.DO.Debug())
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) WithContext(ctx context.Context) *libraryQaOptionDo {
|
|
|
return l.withDO(l.DO.WithContext(ctx))
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) ReadDB() *libraryQaOptionDo {
|
|
|
return l.Clauses(dbresolver.Read)
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) WriteDB() *libraryQaOptionDo {
|
|
|
return l.Clauses(dbresolver.Write)
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Session(config *gorm.Session) *libraryQaOptionDo {
|
|
|
return l.withDO(l.DO.Session(config))
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Clauses(conds ...clause.Expression) *libraryQaOptionDo {
|
|
|
return l.withDO(l.DO.Clauses(conds...))
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Returning(value interface{}, columns ...string) *libraryQaOptionDo {
|
|
|
return l.withDO(l.DO.Returning(value, columns...))
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Not(conds ...gen.Condition) *libraryQaOptionDo {
|
|
|
return l.withDO(l.DO.Not(conds...))
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Or(conds ...gen.Condition) *libraryQaOptionDo {
|
|
|
return l.withDO(l.DO.Or(conds...))
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Select(conds ...field.Expr) *libraryQaOptionDo {
|
|
|
return l.withDO(l.DO.Select(conds...))
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Where(conds ...gen.Condition) *libraryQaOptionDo {
|
|
|
return l.withDO(l.DO.Where(conds...))
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) *libraryQaOptionDo {
|
|
|
return l.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Order(conds ...field.Expr) *libraryQaOptionDo {
|
|
|
return l.withDO(l.DO.Order(conds...))
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Distinct(cols ...field.Expr) *libraryQaOptionDo {
|
|
|
return l.withDO(l.DO.Distinct(cols...))
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Omit(cols ...field.Expr) *libraryQaOptionDo {
|
|
|
return l.withDO(l.DO.Omit(cols...))
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Join(table schema.Tabler, on ...field.Expr) *libraryQaOptionDo {
|
|
|
return l.withDO(l.DO.Join(table, on...))
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) LeftJoin(table schema.Tabler, on ...field.Expr) *libraryQaOptionDo {
|
|
|
return l.withDO(l.DO.LeftJoin(table, on...))
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) RightJoin(table schema.Tabler, on ...field.Expr) *libraryQaOptionDo {
|
|
|
return l.withDO(l.DO.RightJoin(table, on...))
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Group(cols ...field.Expr) *libraryQaOptionDo {
|
|
|
return l.withDO(l.DO.Group(cols...))
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Having(conds ...gen.Condition) *libraryQaOptionDo {
|
|
|
return l.withDO(l.DO.Having(conds...))
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Limit(limit int) *libraryQaOptionDo {
|
|
|
return l.withDO(l.DO.Limit(limit))
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Offset(offset int) *libraryQaOptionDo {
|
|
|
return l.withDO(l.DO.Offset(offset))
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *libraryQaOptionDo {
|
|
|
return l.withDO(l.DO.Scopes(funcs...))
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Unscoped() *libraryQaOptionDo {
|
|
|
return l.withDO(l.DO.Unscoped())
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Create(values ...*model.LibraryQaOption) error {
|
|
|
if len(values) == 0 {
|
|
|
return nil
|
|
|
}
|
|
|
return l.DO.Create(values)
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) CreateInBatches(values []*model.LibraryQaOption, batchSize int) error {
|
|
|
return l.DO.CreateInBatches(values, batchSize)
|
|
|
}
|
|
|
|
|
|
// Save : !!! underlying implementation is different with GORM
|
|
|
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
|
|
func (l libraryQaOptionDo) Save(values ...*model.LibraryQaOption) error {
|
|
|
if len(values) == 0 {
|
|
|
return nil
|
|
|
}
|
|
|
return l.DO.Save(values)
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) First() (*model.LibraryQaOption, error) {
|
|
|
if result, err := l.DO.First(); err != nil {
|
|
|
return nil, err
|
|
|
} else {
|
|
|
return result.(*model.LibraryQaOption), nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Take() (*model.LibraryQaOption, error) {
|
|
|
if result, err := l.DO.Take(); err != nil {
|
|
|
return nil, err
|
|
|
} else {
|
|
|
return result.(*model.LibraryQaOption), nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Last() (*model.LibraryQaOption, error) {
|
|
|
if result, err := l.DO.Last(); err != nil {
|
|
|
return nil, err
|
|
|
} else {
|
|
|
return result.(*model.LibraryQaOption), nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Find() ([]*model.LibraryQaOption, error) {
|
|
|
result, err := l.DO.Find()
|
|
|
return result.([]*model.LibraryQaOption), err
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.LibraryQaOption, err error) {
|
|
|
buf := make([]*model.LibraryQaOption, 0, batchSize)
|
|
|
err = l.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
|
|
defer func() { results = append(results, buf...) }()
|
|
|
return fc(tx, batch)
|
|
|
})
|
|
|
return results, err
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) FindInBatches(result *[]*model.LibraryQaOption, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
|
|
return l.DO.FindInBatches(result, batchSize, fc)
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Attrs(attrs ...field.AssignExpr) *libraryQaOptionDo {
|
|
|
return l.withDO(l.DO.Attrs(attrs...))
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Assign(attrs ...field.AssignExpr) *libraryQaOptionDo {
|
|
|
return l.withDO(l.DO.Assign(attrs...))
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Joins(fields ...field.RelationField) *libraryQaOptionDo {
|
|
|
for _, _f := range fields {
|
|
|
l = *l.withDO(l.DO.Joins(_f))
|
|
|
}
|
|
|
return &l
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Preload(fields ...field.RelationField) *libraryQaOptionDo {
|
|
|
for _, _f := range fields {
|
|
|
l = *l.withDO(l.DO.Preload(_f))
|
|
|
}
|
|
|
return &l
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) FirstOrInit() (*model.LibraryQaOption, error) {
|
|
|
if result, err := l.DO.FirstOrInit(); err != nil {
|
|
|
return nil, err
|
|
|
} else {
|
|
|
return result.(*model.LibraryQaOption), nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) FirstOrCreate() (*model.LibraryQaOption, error) {
|
|
|
if result, err := l.DO.FirstOrCreate(); err != nil {
|
|
|
return nil, err
|
|
|
} else {
|
|
|
return result.(*model.LibraryQaOption), nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) FindByPage(offset int, limit int) (result []*model.LibraryQaOption, count int64, err error) {
|
|
|
result, err = l.Offset(offset).Limit(limit).Find()
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if size := len(result); 0 < limit && 0 < size && size < limit {
|
|
|
count = int64(size + offset)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
count, err = l.Offset(-1).Limit(-1).Count()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
|
|
count, err = l.Count()
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
err = l.Offset(offset).Limit(limit).Scan(result)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Scan(result interface{}) (err error) {
|
|
|
return l.DO.Scan(result)
|
|
|
}
|
|
|
|
|
|
func (l libraryQaOptionDo) Delete(models ...*model.LibraryQaOption) (result gen.ResultInfo, err error) {
|
|
|
return l.DO.Delete(models)
|
|
|
}
|
|
|
|
|
|
func (l *libraryQaOptionDo) withDO(do gen.Dao) *libraryQaOptionDo {
|
|
|
l.DO = *do.(*gen.DO)
|
|
|
return l
|
|
|
}
|