// Code generated by goctl. DO NOT EDIT. package model import ( "context" "database/sql" "fmt" "strings" "github.com/zeromicro/go-zero/core/stores/builder" "github.com/zeromicro/go-zero/core/stores/sqlc" "github.com/zeromicro/go-zero/core/stores/sqlx" "github.com/zeromicro/go-zero/core/stringx" ) var ( fsCanteenProductFieldNames = builder.RawFieldNames(&FsCanteenProduct{}) fsCanteenProductRows = strings.Join(fsCanteenProductFieldNames, ",") fsCanteenProductRowsExpectAutoSet = strings.Join(stringx.Remove(fsCanteenProductFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",") fsCanteenProductRowsWithPlaceHolder = strings.Join(stringx.Remove(fsCanteenProductFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?" ) type ( fsCanteenProductModel interface { Insert(ctx context.Context, data *FsCanteenProduct) (sql.Result, error) FindOne(ctx context.Context, id int64) (*FsCanteenProduct, error) Update(ctx context.Context, data *FsCanteenProduct) error Delete(ctx context.Context, id int64) error } defaultFsCanteenProductModel struct { conn sqlx.SqlConn table string } FsCanteenProduct struct { Id int64 `db:"id"` // ID CanteenType int64 `db:"canteen_type"` // 餐厅类别id ProductId int64 `db:"product_id"` // 产品id SizeId int64 `db:"size_id"` // 尺寸id Sort int64 `db:"sort"` // 排序 Status int64 `db:"status"` // 状态位 1启用0停用 Ctime int64 `db:"ctime"` // 添加时间 Sid string `db:"sid"` // 前端带入的id } ) func newFsCanteenProductModel(conn sqlx.SqlConn) *defaultFsCanteenProductModel { return &defaultFsCanteenProductModel{ conn: conn, table: "`fs_canteen_product`", } } func (m *defaultFsCanteenProductModel) Delete(ctx context.Context, id int64) error { query := fmt.Sprintf("delete from %s where `id` = ?", m.table) _, err := m.conn.ExecCtx(ctx, query, id) return err } func (m *defaultFsCanteenProductModel) FindOne(ctx context.Context, id int64) (*FsCanteenProduct, error) { query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsCanteenProductRows, m.table) var resp FsCanteenProduct err := m.conn.QueryRowCtx(ctx, &resp, query, id) switch err { case nil: return &resp, nil case sqlc.ErrNotFound: return nil, ErrNotFound default: return nil, err } } func (m *defaultFsCanteenProductModel) Insert(ctx context.Context, data *FsCanteenProduct) (sql.Result, error) { query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?)", m.table, fsCanteenProductRowsExpectAutoSet) ret, err := m.conn.ExecCtx(ctx, query, data.CanteenType, data.ProductId, data.SizeId, data.Sort, data.Status, data.Ctime, data.Sid) return ret, err } func (m *defaultFsCanteenProductModel) Update(ctx context.Context, data *FsCanteenProduct) error { query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsCanteenProductRowsWithPlaceHolder) _, err := m.conn.ExecCtx(ctx, query, data.CanteenType, data.ProductId, data.SizeId, data.Sort, data.Status, data.Ctime, data.Sid, data.Id) return err } func (m *defaultFsCanteenProductModel) tableName() string { return m.table }