545 lines
15 KiB
Go
545 lines
15 KiB
Go
// 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 queries
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/clause"
|
|
"gorm.io/gorm/schema"
|
|
|
|
"gorm.io/gen"
|
|
"gorm.io/gen/field"
|
|
|
|
"gorm.io/plugin/dbresolver"
|
|
|
|
"platform/web/models"
|
|
)
|
|
|
|
func newProductSkuUser(db *gorm.DB, opts ...gen.DOOption) productSkuUser {
|
|
_productSkuUser := productSkuUser{}
|
|
|
|
_productSkuUser.productSkuUserDo.UseDB(db, opts...)
|
|
_productSkuUser.productSkuUserDo.UseModel(&models.ProductSkuUser{})
|
|
|
|
tableName := _productSkuUser.productSkuUserDo.TableName()
|
|
_productSkuUser.ALL = field.NewAsterisk(tableName)
|
|
_productSkuUser.ID = field.NewInt32(tableName, "id")
|
|
_productSkuUser.UserID = field.NewInt32(tableName, "user_id")
|
|
_productSkuUser.ProductSkuID = field.NewInt32(tableName, "product_sku_id")
|
|
_productSkuUser.Price = field.NewField(tableName, "price")
|
|
_productSkuUser.Discount = field.NewFloat32(tableName, "discount")
|
|
_productSkuUser.CreatedAt = field.NewTime(tableName, "created_at")
|
|
_productSkuUser.UpdatedAt = field.NewTime(tableName, "updated_at")
|
|
_productSkuUser.User = productSkuUserBelongsToUser{
|
|
db: db.Session(&gorm.Session{}),
|
|
|
|
RelationField: field.NewRelation("User", "models.User"),
|
|
Admin: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("User.Admin", "models.Admin"),
|
|
},
|
|
}
|
|
|
|
_productSkuUser.ProductSku = productSkuUserBelongsToProductSku{
|
|
db: db.Session(&gorm.Session{}),
|
|
|
|
RelationField: field.NewRelation("ProductSku", "models.ProductSku"),
|
|
Product: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("ProductSku.Product", "models.Product"),
|
|
},
|
|
}
|
|
|
|
_productSkuUser.fillFieldMap()
|
|
|
|
return _productSkuUser
|
|
}
|
|
|
|
type productSkuUser struct {
|
|
productSkuUserDo
|
|
|
|
ALL field.Asterisk
|
|
ID field.Int32
|
|
UserID field.Int32
|
|
ProductSkuID field.Int32
|
|
Price field.Field
|
|
Discount field.Float32
|
|
CreatedAt field.Time
|
|
UpdatedAt field.Time
|
|
User productSkuUserBelongsToUser
|
|
|
|
ProductSku productSkuUserBelongsToProductSku
|
|
|
|
fieldMap map[string]field.Expr
|
|
}
|
|
|
|
func (p productSkuUser) Table(newTableName string) *productSkuUser {
|
|
p.productSkuUserDo.UseTable(newTableName)
|
|
return p.updateTableName(newTableName)
|
|
}
|
|
|
|
func (p productSkuUser) As(alias string) *productSkuUser {
|
|
p.productSkuUserDo.DO = *(p.productSkuUserDo.As(alias).(*gen.DO))
|
|
return p.updateTableName(alias)
|
|
}
|
|
|
|
func (p *productSkuUser) updateTableName(table string) *productSkuUser {
|
|
p.ALL = field.NewAsterisk(table)
|
|
p.ID = field.NewInt32(table, "id")
|
|
p.UserID = field.NewInt32(table, "user_id")
|
|
p.ProductSkuID = field.NewInt32(table, "product_sku_id")
|
|
p.Price = field.NewField(table, "price")
|
|
p.Discount = field.NewFloat32(table, "discount")
|
|
p.CreatedAt = field.NewTime(table, "created_at")
|
|
p.UpdatedAt = field.NewTime(table, "updated_at")
|
|
|
|
p.fillFieldMap()
|
|
|
|
return p
|
|
}
|
|
|
|
func (p *productSkuUser) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
|
_f, ok := p.fieldMap[fieldName]
|
|
if !ok || _f == nil {
|
|
return nil, false
|
|
}
|
|
_oe, ok := _f.(field.OrderExpr)
|
|
return _oe, ok
|
|
}
|
|
|
|
func (p *productSkuUser) fillFieldMap() {
|
|
p.fieldMap = make(map[string]field.Expr, 9)
|
|
p.fieldMap["id"] = p.ID
|
|
p.fieldMap["user_id"] = p.UserID
|
|
p.fieldMap["product_sku_id"] = p.ProductSkuID
|
|
p.fieldMap["price"] = p.Price
|
|
p.fieldMap["discount"] = p.Discount
|
|
p.fieldMap["created_at"] = p.CreatedAt
|
|
p.fieldMap["updated_at"] = p.UpdatedAt
|
|
|
|
}
|
|
|
|
func (p productSkuUser) clone(db *gorm.DB) productSkuUser {
|
|
p.productSkuUserDo.ReplaceConnPool(db.Statement.ConnPool)
|
|
p.User.db = db.Session(&gorm.Session{Initialized: true})
|
|
p.User.db.Statement.ConnPool = db.Statement.ConnPool
|
|
p.ProductSku.db = db.Session(&gorm.Session{Initialized: true})
|
|
p.ProductSku.db.Statement.ConnPool = db.Statement.ConnPool
|
|
return p
|
|
}
|
|
|
|
func (p productSkuUser) replaceDB(db *gorm.DB) productSkuUser {
|
|
p.productSkuUserDo.ReplaceDB(db)
|
|
p.User.db = db.Session(&gorm.Session{})
|
|
p.ProductSku.db = db.Session(&gorm.Session{})
|
|
return p
|
|
}
|
|
|
|
type productSkuUserBelongsToUser struct {
|
|
db *gorm.DB
|
|
|
|
field.RelationField
|
|
|
|
Admin struct {
|
|
field.RelationField
|
|
}
|
|
}
|
|
|
|
func (a productSkuUserBelongsToUser) Where(conds ...field.Expr) *productSkuUserBelongsToUser {
|
|
if len(conds) == 0 {
|
|
return &a
|
|
}
|
|
|
|
exprs := make([]clause.Expression, 0, len(conds))
|
|
for _, cond := range conds {
|
|
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
|
}
|
|
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
|
return &a
|
|
}
|
|
|
|
func (a productSkuUserBelongsToUser) WithContext(ctx context.Context) *productSkuUserBelongsToUser {
|
|
a.db = a.db.WithContext(ctx)
|
|
return &a
|
|
}
|
|
|
|
func (a productSkuUserBelongsToUser) Session(session *gorm.Session) *productSkuUserBelongsToUser {
|
|
a.db = a.db.Session(session)
|
|
return &a
|
|
}
|
|
|
|
func (a productSkuUserBelongsToUser) Model(m *models.ProductSkuUser) *productSkuUserBelongsToUserTx {
|
|
return &productSkuUserBelongsToUserTx{a.db.Model(m).Association(a.Name())}
|
|
}
|
|
|
|
func (a productSkuUserBelongsToUser) Unscoped() *productSkuUserBelongsToUser {
|
|
a.db = a.db.Unscoped()
|
|
return &a
|
|
}
|
|
|
|
type productSkuUserBelongsToUserTx struct{ tx *gorm.Association }
|
|
|
|
func (a productSkuUserBelongsToUserTx) Find() (result *models.User, err error) {
|
|
return result, a.tx.Find(&result)
|
|
}
|
|
|
|
func (a productSkuUserBelongsToUserTx) Append(values ...*models.User) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Append(targetValues...)
|
|
}
|
|
|
|
func (a productSkuUserBelongsToUserTx) Replace(values ...*models.User) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Replace(targetValues...)
|
|
}
|
|
|
|
func (a productSkuUserBelongsToUserTx) Delete(values ...*models.User) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Delete(targetValues...)
|
|
}
|
|
|
|
func (a productSkuUserBelongsToUserTx) Clear() error {
|
|
return a.tx.Clear()
|
|
}
|
|
|
|
func (a productSkuUserBelongsToUserTx) Count() int64 {
|
|
return a.tx.Count()
|
|
}
|
|
|
|
func (a productSkuUserBelongsToUserTx) Unscoped() *productSkuUserBelongsToUserTx {
|
|
a.tx = a.tx.Unscoped()
|
|
return &a
|
|
}
|
|
|
|
type productSkuUserBelongsToProductSku struct {
|
|
db *gorm.DB
|
|
|
|
field.RelationField
|
|
|
|
Product struct {
|
|
field.RelationField
|
|
}
|
|
}
|
|
|
|
func (a productSkuUserBelongsToProductSku) Where(conds ...field.Expr) *productSkuUserBelongsToProductSku {
|
|
if len(conds) == 0 {
|
|
return &a
|
|
}
|
|
|
|
exprs := make([]clause.Expression, 0, len(conds))
|
|
for _, cond := range conds {
|
|
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
|
}
|
|
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
|
return &a
|
|
}
|
|
|
|
func (a productSkuUserBelongsToProductSku) WithContext(ctx context.Context) *productSkuUserBelongsToProductSku {
|
|
a.db = a.db.WithContext(ctx)
|
|
return &a
|
|
}
|
|
|
|
func (a productSkuUserBelongsToProductSku) Session(session *gorm.Session) *productSkuUserBelongsToProductSku {
|
|
a.db = a.db.Session(session)
|
|
return &a
|
|
}
|
|
|
|
func (a productSkuUserBelongsToProductSku) Model(m *models.ProductSkuUser) *productSkuUserBelongsToProductSkuTx {
|
|
return &productSkuUserBelongsToProductSkuTx{a.db.Model(m).Association(a.Name())}
|
|
}
|
|
|
|
func (a productSkuUserBelongsToProductSku) Unscoped() *productSkuUserBelongsToProductSku {
|
|
a.db = a.db.Unscoped()
|
|
return &a
|
|
}
|
|
|
|
type productSkuUserBelongsToProductSkuTx struct{ tx *gorm.Association }
|
|
|
|
func (a productSkuUserBelongsToProductSkuTx) Find() (result *models.ProductSku, err error) {
|
|
return result, a.tx.Find(&result)
|
|
}
|
|
|
|
func (a productSkuUserBelongsToProductSkuTx) Append(values ...*models.ProductSku) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Append(targetValues...)
|
|
}
|
|
|
|
func (a productSkuUserBelongsToProductSkuTx) Replace(values ...*models.ProductSku) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Replace(targetValues...)
|
|
}
|
|
|
|
func (a productSkuUserBelongsToProductSkuTx) Delete(values ...*models.ProductSku) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Delete(targetValues...)
|
|
}
|
|
|
|
func (a productSkuUserBelongsToProductSkuTx) Clear() error {
|
|
return a.tx.Clear()
|
|
}
|
|
|
|
func (a productSkuUserBelongsToProductSkuTx) Count() int64 {
|
|
return a.tx.Count()
|
|
}
|
|
|
|
func (a productSkuUserBelongsToProductSkuTx) Unscoped() *productSkuUserBelongsToProductSkuTx {
|
|
a.tx = a.tx.Unscoped()
|
|
return &a
|
|
}
|
|
|
|
type productSkuUserDo struct{ gen.DO }
|
|
|
|
func (p productSkuUserDo) Debug() *productSkuUserDo {
|
|
return p.withDO(p.DO.Debug())
|
|
}
|
|
|
|
func (p productSkuUserDo) WithContext(ctx context.Context) *productSkuUserDo {
|
|
return p.withDO(p.DO.WithContext(ctx))
|
|
}
|
|
|
|
func (p productSkuUserDo) ReadDB() *productSkuUserDo {
|
|
return p.Clauses(dbresolver.Read)
|
|
}
|
|
|
|
func (p productSkuUserDo) WriteDB() *productSkuUserDo {
|
|
return p.Clauses(dbresolver.Write)
|
|
}
|
|
|
|
func (p productSkuUserDo) Session(config *gorm.Session) *productSkuUserDo {
|
|
return p.withDO(p.DO.Session(config))
|
|
}
|
|
|
|
func (p productSkuUserDo) Clauses(conds ...clause.Expression) *productSkuUserDo {
|
|
return p.withDO(p.DO.Clauses(conds...))
|
|
}
|
|
|
|
func (p productSkuUserDo) Returning(value interface{}, columns ...string) *productSkuUserDo {
|
|
return p.withDO(p.DO.Returning(value, columns...))
|
|
}
|
|
|
|
func (p productSkuUserDo) Not(conds ...gen.Condition) *productSkuUserDo {
|
|
return p.withDO(p.DO.Not(conds...))
|
|
}
|
|
|
|
func (p productSkuUserDo) Or(conds ...gen.Condition) *productSkuUserDo {
|
|
return p.withDO(p.DO.Or(conds...))
|
|
}
|
|
|
|
func (p productSkuUserDo) Select(conds ...field.Expr) *productSkuUserDo {
|
|
return p.withDO(p.DO.Select(conds...))
|
|
}
|
|
|
|
func (p productSkuUserDo) Where(conds ...gen.Condition) *productSkuUserDo {
|
|
return p.withDO(p.DO.Where(conds...))
|
|
}
|
|
|
|
func (p productSkuUserDo) Order(conds ...field.Expr) *productSkuUserDo {
|
|
return p.withDO(p.DO.Order(conds...))
|
|
}
|
|
|
|
func (p productSkuUserDo) Distinct(cols ...field.Expr) *productSkuUserDo {
|
|
return p.withDO(p.DO.Distinct(cols...))
|
|
}
|
|
|
|
func (p productSkuUserDo) Omit(cols ...field.Expr) *productSkuUserDo {
|
|
return p.withDO(p.DO.Omit(cols...))
|
|
}
|
|
|
|
func (p productSkuUserDo) Join(table schema.Tabler, on ...field.Expr) *productSkuUserDo {
|
|
return p.withDO(p.DO.Join(table, on...))
|
|
}
|
|
|
|
func (p productSkuUserDo) LeftJoin(table schema.Tabler, on ...field.Expr) *productSkuUserDo {
|
|
return p.withDO(p.DO.LeftJoin(table, on...))
|
|
}
|
|
|
|
func (p productSkuUserDo) RightJoin(table schema.Tabler, on ...field.Expr) *productSkuUserDo {
|
|
return p.withDO(p.DO.RightJoin(table, on...))
|
|
}
|
|
|
|
func (p productSkuUserDo) Group(cols ...field.Expr) *productSkuUserDo {
|
|
return p.withDO(p.DO.Group(cols...))
|
|
}
|
|
|
|
func (p productSkuUserDo) Having(conds ...gen.Condition) *productSkuUserDo {
|
|
return p.withDO(p.DO.Having(conds...))
|
|
}
|
|
|
|
func (p productSkuUserDo) Limit(limit int) *productSkuUserDo {
|
|
return p.withDO(p.DO.Limit(limit))
|
|
}
|
|
|
|
func (p productSkuUserDo) Offset(offset int) *productSkuUserDo {
|
|
return p.withDO(p.DO.Offset(offset))
|
|
}
|
|
|
|
func (p productSkuUserDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *productSkuUserDo {
|
|
return p.withDO(p.DO.Scopes(funcs...))
|
|
}
|
|
|
|
func (p productSkuUserDo) Unscoped() *productSkuUserDo {
|
|
return p.withDO(p.DO.Unscoped())
|
|
}
|
|
|
|
func (p productSkuUserDo) Create(values ...*models.ProductSkuUser) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return p.DO.Create(values)
|
|
}
|
|
|
|
func (p productSkuUserDo) CreateInBatches(values []*models.ProductSkuUser, batchSize int) error {
|
|
return p.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 (p productSkuUserDo) Save(values ...*models.ProductSkuUser) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return p.DO.Save(values)
|
|
}
|
|
|
|
func (p productSkuUserDo) First() (*models.ProductSkuUser, error) {
|
|
if result, err := p.DO.First(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.ProductSkuUser), nil
|
|
}
|
|
}
|
|
|
|
func (p productSkuUserDo) Take() (*models.ProductSkuUser, error) {
|
|
if result, err := p.DO.Take(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.ProductSkuUser), nil
|
|
}
|
|
}
|
|
|
|
func (p productSkuUserDo) Last() (*models.ProductSkuUser, error) {
|
|
if result, err := p.DO.Last(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.ProductSkuUser), nil
|
|
}
|
|
}
|
|
|
|
func (p productSkuUserDo) Find() ([]*models.ProductSkuUser, error) {
|
|
result, err := p.DO.Find()
|
|
return result.([]*models.ProductSkuUser), err
|
|
}
|
|
|
|
func (p productSkuUserDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.ProductSkuUser, err error) {
|
|
buf := make([]*models.ProductSkuUser, 0, batchSize)
|
|
err = p.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 (p productSkuUserDo) FindInBatches(result *[]*models.ProductSkuUser, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
|
return p.DO.FindInBatches(result, batchSize, fc)
|
|
}
|
|
|
|
func (p productSkuUserDo) Attrs(attrs ...field.AssignExpr) *productSkuUserDo {
|
|
return p.withDO(p.DO.Attrs(attrs...))
|
|
}
|
|
|
|
func (p productSkuUserDo) Assign(attrs ...field.AssignExpr) *productSkuUserDo {
|
|
return p.withDO(p.DO.Assign(attrs...))
|
|
}
|
|
|
|
func (p productSkuUserDo) Joins(fields ...field.RelationField) *productSkuUserDo {
|
|
for _, _f := range fields {
|
|
p = *p.withDO(p.DO.Joins(_f))
|
|
}
|
|
return &p
|
|
}
|
|
|
|
func (p productSkuUserDo) Preload(fields ...field.RelationField) *productSkuUserDo {
|
|
for _, _f := range fields {
|
|
p = *p.withDO(p.DO.Preload(_f))
|
|
}
|
|
return &p
|
|
}
|
|
|
|
func (p productSkuUserDo) FirstOrInit() (*models.ProductSkuUser, error) {
|
|
if result, err := p.DO.FirstOrInit(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.ProductSkuUser), nil
|
|
}
|
|
}
|
|
|
|
func (p productSkuUserDo) FirstOrCreate() (*models.ProductSkuUser, error) {
|
|
if result, err := p.DO.FirstOrCreate(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.ProductSkuUser), nil
|
|
}
|
|
}
|
|
|
|
func (p productSkuUserDo) FindByPage(offset int, limit int) (result []*models.ProductSkuUser, count int64, err error) {
|
|
result, err = p.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 = p.Offset(-1).Limit(-1).Count()
|
|
return
|
|
}
|
|
|
|
func (p productSkuUserDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
|
count, err = p.Count()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
err = p.Offset(offset).Limit(limit).Scan(result)
|
|
return
|
|
}
|
|
|
|
func (p productSkuUserDo) Scan(result interface{}) (err error) {
|
|
return p.DO.Scan(result)
|
|
}
|
|
|
|
func (p productSkuUserDo) Delete(models ...*models.ProductSkuUser) (result gen.ResultInfo, err error) {
|
|
return p.DO.Delete(models)
|
|
}
|
|
|
|
func (p *productSkuUserDo) withDO(do gen.Dao) *productSkuUserDo {
|
|
p.DO = *do.(*gen.DO)
|
|
return p
|
|
}
|