// ==========================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================

package internal

import (
	"context"
	"github.com/gogf/gf/database/gdb"
	"github.com/gogf/gf/frame/g"
)

// ProductDao is the manager for logic model data accessing and custom defined data operations functions management.
type ProductDao struct {
	Table   string         // Table is the underlying table name of the DAO.
	Group   string         // Group is the database configuration group name of current DAO.
	Columns ProductColumns // Columns is the short type for Columns, which contains all the column names of Table for convenient usage.
}

// ProductColumns defines and stores column names for table product.
type ProductColumns struct {
	ProductId            string //
	ProductName          string // 商品名称
	ProductType          string // 商品类型 1：实物 ，2：商品，3：线下
	ProductClassify      string // 商品分类id(info_product_classifyh表id)
	ProductPrice         string // 商品价格
	ProductSpecification string // 商品规格
	CreatedAt            string // 创建时间
	CreatPeople          string // 创建人
	UpdatedAt            string // 更新时间
	UpdatePeople         string // 更新人
}

//  productColumns holds the columns for table product.
var productColumns = ProductColumns{
	ProductId:            "product_id",
	ProductName:          "product_name",
	ProductType:          "product_type",
	ProductClassify:      "product_classify",
	ProductPrice:         "product_price",
	ProductSpecification: "product_specification",
	CreatedAt:            "created_at",
	CreatPeople:          "creat_people",
	UpdatedAt:            "updated_at",
	UpdatePeople:         "update_people",
}

// NewProductDao creates and returns a new DAO object for table data access.
func NewProductDao() *ProductDao {
	return &ProductDao{
		Group:   "default",
		Table:   "product",
		Columns: productColumns,
	}
}

// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *ProductDao) DB() gdb.DB {
	return g.DB(dao.Group)
}

// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *ProductDao) Ctx(ctx context.Context) *gdb.Model {
	return dao.DB().Model(dao.Table).Safe().Ctx(ctx)
}

// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *ProductDao) Transaction(ctx context.Context, f func(ctx context.Context, tx *gdb.TX) error) (err error) {
	return dao.Ctx(ctx).Transaction(ctx, f)
}
