// 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 ( fsProductSizeFieldNames = builder.RawFieldNames(&FsProductSize{}) fsProductSizeRows = strings.Join(fsProductSizeFieldNames, ",") fsProductSizeRowsExpectAutoSet = strings.Join(stringx.Remove(fsProductSizeFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",") fsProductSizeRowsWithPlaceHolder = strings.Join(stringx.Remove(fsProductSizeFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?" ) type ( fsProductSizeModel interface { Insert(ctx context.Context, data *FsProductSize) (sql.Result, error) FindOne(ctx context.Context, id int64) (*FsProductSize, error) Update(ctx context.Context, data *FsProductSize) error Delete(ctx context.Context, id int64) error CountByStatus(ctx context.Context, status int) (total int, err error) FindAllByStatus(ctx context.Context, status int, sort int) ([]FsProductSize, error) } defaultFsProductSizeModel struct { conn sqlx.SqlConn table string } FsProductSize struct { Id int64 `db:"id"` ProductId int64 `db:"product_id"` // 产品ID Title string `db:"title"` // 标题 10*10*20 Cover sql.NullString `db:"cover"` // 封面图 CoverImg sql.NullString `db:"cover_img"` // 背景图 Capacity string `db:"capacity"` // 自己填的尺寸名称 Status int64 `db:"status"` // 状态位 显示 删除 Sort int64 `db:"sort"` // 排序 Remark sql.NullString `db:"remark"` // 备注信息 PartsCanDeleted int64 `db:"parts_can_deleted"` // 配件是否可移除 1是0否 } ) func newFsProductSizeModel(conn sqlx.SqlConn) *defaultFsProductSizeModel { return &defaultFsProductSizeModel{ conn: conn, table: "`fs_product_size`", } } func (m *defaultFsProductSizeModel) 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 *defaultFsProductSizeModel) FindOne(ctx context.Context, id int64) (*FsProductSize, error) { query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsProductSizeRows, m.table) var resp FsProductSize 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 *defaultFsProductSizeModel) Insert(ctx context.Context, data *FsProductSize) (sql.Result, error) { query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, fsProductSizeRowsExpectAutoSet) ret, err := m.conn.ExecCtx(ctx, query, data.ProductId, data.Title, data.Cover, data.CoverImg, data.Capacity, data.Status, data.Sort, data.Remark, data.PartsCanDeleted) return ret, err } func (m *defaultFsProductSizeModel) Update(ctx context.Context, data *FsProductSize) error { query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsProductSizeRowsWithPlaceHolder) _, err := m.conn.ExecCtx(ctx, query, data.ProductId, data.Title, data.Cover, data.CoverImg, data.Capacity, data.Status, data.Sort, data.Remark, data.PartsCanDeleted, data.Id) return err } func (m *defaultFsProductSizeModel) CountByStatus(ctx context.Context, status int) (total int, err error) { query := fmt.Sprintf("select %s from %s where `status` = ? limit 1", "count(*) as num", m.table) err = m.conn.QueryRowCtx(ctx, &total, query, status) if err != nil { return 0, err } return } func (m *defaultFsProductSizeModel) FindAllByStatus(ctx context.Context, status int, sort int) (resp []FsProductSize, err error) { query := fmt.Sprintf("select %s from %s where `status` = ? ", fsProductSizeRows, m.table) switch sort { case 1: query = fmt.Sprintf("%s order by `sort` ASC", query) case 2: query = fmt.Sprintf("%s order by `sort` DESC", query) } err = m.conn.QueryRowsCtx(ctx, &resp, query, status) if err != nil { return nil, err } return } func (m *defaultFsProductSizeModel) tableName() string { return m.table }