// 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 ( fsCanteenTypeFieldNames = builder.RawFieldNames(&FsCanteenType{}) fsCanteenTypeRows = strings.Join(fsCanteenTypeFieldNames, ",") // fsCanteenTypeGetTypeRows = strings.Join(stringx.Remove(fsCanteenTypeFieldNames, "`id`", "`name`", "`sort`", "`created_at`", "`status`"), ",") // fsCanteenTypeGetTypeRows = builder.RawFieldNames(&FsGetTypeCanteenType{}) fsCanteenTypeRowsExpectAutoSet = strings.Join(stringx.Remove(fsCanteenTypeFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",") fsCanteenTypeRowsWithPlaceHolder = strings.Join(stringx.Remove(fsCanteenTypeFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?" ) type ( fsCanteenTypeModel interface { Insert(ctx context.Context, data *FsCanteenType) (sql.Result, error) FindOne(ctx context.Context, id int64) (*FsCanteenType, error) Update(ctx context.Context, data *FsCanteenType) error Delete(ctx context.Context, id int64) error FindGetType(ctx context.Context) ([]*FsGetTypeCanteenType, error) } defaultFsCanteenTypeModel struct { conn sqlx.SqlConn table string } FsCanteenType struct { Id int64 `db:"id"` // ID Name string `db:"name"` // 餐厅名字 Sort int64 `db:"sort"` // 排序 Status int64 `db:"status"` // 状态位 1启用0停用 Ctime int64 `db:"ctime"` // 添加时间 } FsGetTypeCanteenType struct { Id int64 `db:"id" json:"key"` // ID Name string `db:"name" json:"name"` // 餐厅名字 } ) func newFsCanteenTypeModel(conn sqlx.SqlConn) *defaultFsCanteenTypeModel { return &defaultFsCanteenTypeModel{ conn: conn, table: "`fs_canteen_type`", } } func (m *defaultFsCanteenTypeModel) 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 *defaultFsCanteenTypeModel) FindOne(ctx context.Context, id int64) (*FsCanteenType, error) { query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsCanteenTypeRows, m.table) var resp FsCanteenType 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 *defaultFsCanteenTypeModel) FindGetType(ctx context.Context) ([]*FsGetTypeCanteenType, error) { query := fmt.Sprintf("select X.id,X.name from (select %s from %s where status = 1 order by sort desc) X", fsCanteenTypeRows, m.table) var resp []*FsGetTypeCanteenType err := m.conn.QueryRows(&resp, query) switch err { case nil: return resp, nil case sqlc.ErrNotFound: return nil, ErrNotFound default: return nil, err } } func (m *defaultFsCanteenTypeModel) Insert(ctx context.Context, data *FsCanteenType) (sql.Result, error) { query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?)", m.table, fsCanteenTypeRowsExpectAutoSet) ret, err := m.conn.ExecCtx(ctx, query, data.Name, data.Sort, data.Status, data.Ctime) return ret, err } func (m *defaultFsCanteenTypeModel) Update(ctx context.Context, data *FsCanteenType) error { query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsCanteenTypeRowsWithPlaceHolder) _, err := m.conn.ExecCtx(ctx, query, data.Name, data.Sort, data.Status, data.Ctime, data.Id) return err } func (m *defaultFsCanteenTypeModel) tableName() string { return m.table }