muyu-apiserver/model/invproductboltmodel_gen.go

96 lines
3.4 KiB
Go
Raw Permalink Normal View History

package model
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 (
invProductBoltFieldNames = builder.RawFieldNames(&InvProductBolt{})
invProductBoltRows = strings.Join(invProductBoltFieldNames, ",")
invProductBoltRowsExpectAutoSet = strings.Join(stringx.Remove(invProductBoltFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
invProductBoltRowsWithPlaceHolder = strings.Join(stringx.Remove(invProductBoltFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)
type (
invProductBoltModel interface {
Insert(ctx context.Context, data *InvProductBolt) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*InvProductBolt, error)
FindOneByBoltId(ctx context.Context, boltId string) (*InvProductBolt, error)
Update(ctx context.Context, data *InvProductBolt) error
Delete(ctx context.Context, id int64) error
}
defaultInvProductBoltModel struct {
conn sqlx.SqlConn
table string
}
InvProductBolt struct {
Id int64 `db:"id"`
BoltId string `db:"bolt_id"`
PanId string `db:"pan_id"`
LengthM float64 `db:"length_m"`
Color string `db:"color"`
SortOrder int64 `db:"sort_order"`
TenantId string `db:"tenant_id"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}
)
func newInvProductBoltModel(conn sqlx.SqlConn) *defaultInvProductBoltModel {
return &defaultInvProductBoltModel{
conn: conn,
table: "`inv_product_bolt`",
}
}
func (m *defaultInvProductBoltModel) Insert(ctx context.Context, data *InvProductBolt) (sql.Result, error) {
query := fmt.Sprintf("INSERT INTO %s (%s) VALUES (?, ?, ?, ?, ?, ?)", m.table, invProductBoltRowsExpectAutoSet)
return m.conn.ExecCtx(ctx, query, data.BoltId, data.PanId, data.LengthM, data.Color, data.SortOrder, data.TenantId)
}
func (m *defaultInvProductBoltModel) FindOne(ctx context.Context, id int64) (*InvProductBolt, error) {
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? LIMIT 1", invProductBoltRows, m.table)
var resp InvProductBolt
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
if err != nil {
return nil, err
}
return &resp, nil
}
func (m *defaultInvProductBoltModel) FindOneByBoltId(ctx context.Context, boltId string) (*InvProductBolt, error) {
query := fmt.Sprintf("SELECT %s FROM %s WHERE `bolt_id` = ? LIMIT 1", invProductBoltRows, m.table)
var resp InvProductBolt
err := m.conn.QueryRowCtx(ctx, &resp, query, boltId)
if err != nil {
return nil, err
}
return &resp, nil
}
func (m *defaultInvProductBoltModel) Update(ctx context.Context, data *InvProductBolt) error {
query := fmt.Sprintf("UPDATE %s SET %s WHERE `id` = ?", m.table, invProductBoltRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, data.BoltId, data.PanId, data.LengthM, data.Color, data.SortOrder, data.TenantId, data.Id)
return err
}
func (m *defaultInvProductBoltModel) 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 *defaultInvProductBoltModel) tableName() string {
return m.table
}