init
This commit is contained in:
87
model/goods_status/goodsstatusmodel_gen.go
Normal file
87
model/goods_status/goodsstatusmodel_gen.go
Normal file
@ -0,0 +1,87 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// versions:
|
||||
// goctl version: 1.7.6
|
||||
|
||||
package goods_status
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
goodsStatusFieldNames = builder.RawFieldNames(&GoodsStatus{})
|
||||
goodsStatusRows = strings.Join(goodsStatusFieldNames, ",")
|
||||
goodsStatusRowsExpectAutoSet = strings.Join(stringx.Remove(goodsStatusFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
goodsStatusRowsWithPlaceHolder = strings.Join(stringx.Remove(goodsStatusFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
)
|
||||
|
||||
type (
|
||||
goodsStatusModel interface {
|
||||
Insert(ctx context.Context, data *GoodsStatus) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*GoodsStatus, error)
|
||||
Update(ctx context.Context, data *GoodsStatus) error
|
||||
Delete(ctx context.Context, id int64) error
|
||||
}
|
||||
|
||||
defaultGoodsStatusModel struct {
|
||||
conn sqlx.SqlConn
|
||||
table string
|
||||
}
|
||||
|
||||
GoodsStatus struct {
|
||||
Id int64 `db:"id"` // id
|
||||
ApiId sql.NullInt64 `db:"api_id"` // 三方接口
|
||||
ApiProductId sql.NullInt64 `db:"api_product_id"` // 三方商品id
|
||||
Status sql.NullInt64 `db:"status"` // 商品状态 0=上架 1=下架
|
||||
}
|
||||
)
|
||||
|
||||
func newGoodsStatusModel(conn sqlx.SqlConn) *defaultGoodsStatusModel {
|
||||
return &defaultGoodsStatusModel{
|
||||
conn: conn,
|
||||
table: "`goods_status`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultGoodsStatusModel) 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 *defaultGoodsStatusModel) FindOne(ctx context.Context, id int64) (*GoodsStatus, error) {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", goodsStatusRows, m.table)
|
||||
var resp GoodsStatus
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlx.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultGoodsStatusModel) Insert(ctx context.Context, data *GoodsStatus) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?)", m.table, goodsStatusRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.ApiId, data.ApiProductId, data.Status)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultGoodsStatusModel) Update(ctx context.Context, data *GoodsStatus) error {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, goodsStatusRowsWithPlaceHolder)
|
||||
_, err := m.conn.ExecCtx(ctx, query, data.ApiId, data.ApiProductId, data.Status, data.Id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultGoodsStatusModel) tableName() string {
|
||||
return m.table
|
||||
}
|
Reference in New Issue
Block a user