// Code generated by goctl. DO NOT EDIT. package genModel import ( "context" "database/sql" "fmt" "strings" "time" "github.com/zeromicro/go-zero/core/stores/builder" "github.com/zeromicro/go-zero/core/stores/sqlx" "github.com/zeromicro/go-zero/core/stringx" ) var ( serverOrderMarketFieldNames = builder.RawFieldNames(&ServerOrderMarket{}) serverOrderMarketRows = strings.Join(serverOrderMarketFieldNames, ",") serverOrderMarketRowsExpectAutoSet = strings.Join(stringx.Remove(serverOrderMarketFieldNames, "`order_id`", "`create_at`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",") serverOrderMarketRowsWithPlaceHolder = strings.Join(stringx.Remove(serverOrderMarketFieldNames, "`order_id`", "`create_at`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?" ) type ( serverOrderMarketModel interface { Insert(ctx context.Context, data *ServerOrderMarket) (sql.Result, error) FindOne(ctx context.Context, orderId uint64) (*ServerOrderMarket, error) FindByOutBizId(ctx context.Context, outBizId string) (*ServerOrderMarket, error) Update(ctx context.Context, data *ServerOrderMarket) error Delete(ctx context.Context, orderId uint64) error } defaultServerOrderMarketModel struct { conn sqlx.SqlConn table string } ServerOrderMarket struct { OrderId uint64 `db:"order_id"` OutBizNo string `db:"out_biz_no"` // 用户侧流水号 VoucherNum string `db:"voucher_num"` // 商户号 OrderNum string `db:"order_num"` // 系统侧订单号 ProductId string `db:"product_id"` // 平台提供商品id Num int64 `db:"num"` // 购买数量 LogId int64 `db:"log_id"` // 对应的日志id ReqTime time.Time `db:"req_time"` // 请求时间 CreateTime time.Time `db:"create_time"` UpdateTime time.Time `db:"update_time"` Status int64 `db:"status"` // 状态 } ) func newServerOrderMarketModel(conn sqlx.SqlConn) *defaultServerOrderMarketModel { return &defaultServerOrderMarketModel{ conn: conn, table: "`server_order_market`", } } func (m *defaultServerOrderMarketModel) Delete(ctx context.Context, orderId uint64) error { query := fmt.Sprintf("delete from %s where `order_id` = ?", m.table) _, err := m.conn.ExecCtx(ctx, query, orderId) return err } func (m *defaultServerOrderMarketModel) FindByOutBizId(ctx context.Context, outBizId string) (*ServerOrderMarket, error) { query := fmt.Sprintf("select %s from %s where `out_biz_no` = ? limit 1", serverOrderMarketRows, m.table) var resp ServerOrderMarket err := m.conn.QueryRowCtx(ctx, &resp, query, outBizId) switch err { case nil: return &resp, nil case sqlx.ErrNotFound: return nil, ErrNotFound default: return nil, err } } func (m *defaultServerOrderMarketModel) FindOne(ctx context.Context, orderId uint64) (*ServerOrderMarket, error) { query := fmt.Sprintf("select %s from %s where `order_id` = ? limit 1", serverOrderMarketRows, m.table) var resp ServerOrderMarket err := m.conn.QueryRowCtx(ctx, &resp, query, orderId) switch err { case nil: return &resp, nil case sqlx.ErrNotFound: return nil, ErrNotFound default: return nil, err } } func (m *defaultServerOrderMarketModel) Insert(ctx context.Context, data *ServerOrderMarket) (sql.Result, error) { query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?,?)", m.table, serverOrderMarketRowsExpectAutoSet) ret, err := m.conn.ExecCtx(ctx, query, data.OutBizNo, data.VoucherNum, data.OrderNum, data.ProductId, data.Num, data.LogId, data.ReqTime, data.CreateTime, data.Status) return ret, err } func (m *defaultServerOrderMarketModel) Update(ctx context.Context, data *ServerOrderMarket) error { query := fmt.Sprintf("update %s set %s where `order_id` = ?", m.table, serverOrderMarketRowsWithPlaceHolder) _, err := m.conn.ExecCtx(ctx, query, data.OutBizNo, data.VoucherNum, data.OrderNum, data.ProductId, data.Num, data.LogId, data.ReqTime, data.Status, data.OrderId) return err } func (m *defaultServerOrderMarketModel) tableName() string { return m.table }