fix
This commit is contained in:
38
model/fsstandardlogomodel.go
Executable file
38
model/fsstandardlogomodel.go
Executable file
@@ -0,0 +1,38 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ FsStandardLogoModel = (*customFsStandardLogoModel)(nil)
|
||||
|
||||
type (
|
||||
// FsStandardLogoModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customFsStandardLogoModel.
|
||||
FsStandardLogoModel interface {
|
||||
fsStandardLogoModel
|
||||
GetAll(ctx context.Context) (resp []FsStandardLogo, err error)
|
||||
}
|
||||
|
||||
customFsStandardLogoModel struct {
|
||||
*defaultFsStandardLogoModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewFsStandardLogoModel returns a model for the database table.
|
||||
func NewFsStandardLogoModel(conn sqlx.SqlConn) FsStandardLogoModel {
|
||||
return &customFsStandardLogoModel{
|
||||
defaultFsStandardLogoModel: newFsStandardLogoModel(conn),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultFsStandardLogoModel) GetAll(ctx context.Context) (resp []FsStandardLogo, err error) {
|
||||
query := fmt.Sprintf("select %s from %s where `status` = ? ", fsStandardLogoRows, m.table)
|
||||
err = m.conn.QueryRowsCtx(ctx, &resp, query, 1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
87
model/fsstandardlogomodel_gen.go
Executable file
87
model/fsstandardlogomodel_gen.go
Executable file
@@ -0,0 +1,87 @@
|
||||
// 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 (
|
||||
fsStandardLogoFieldNames = builder.RawFieldNames(&FsStandardLogo{})
|
||||
fsStandardLogoRows = strings.Join(fsStandardLogoFieldNames, ",")
|
||||
fsStandardLogoRowsExpectAutoSet = strings.Join(stringx.Remove(fsStandardLogoFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
fsStandardLogoRowsWithPlaceHolder = strings.Join(stringx.Remove(fsStandardLogoFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
)
|
||||
|
||||
type (
|
||||
fsStandardLogoModel interface {
|
||||
Insert(ctx context.Context, data *FsStandardLogo) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*FsStandardLogo, error)
|
||||
Update(ctx context.Context, data *FsStandardLogo) error
|
||||
Delete(ctx context.Context, id int64) error
|
||||
}
|
||||
|
||||
defaultFsStandardLogoModel struct {
|
||||
conn sqlx.SqlConn
|
||||
table string
|
||||
}
|
||||
|
||||
FsStandardLogo struct {
|
||||
Id int64 `db:"id"` // ID
|
||||
Name string `db:"name"` // logo名称
|
||||
Image string `db:"image"` // 图片地址
|
||||
Ctime int64 `db:"ctime"` // 添加时间
|
||||
Status int64 `db:"status"` // 状态 1正常 0删除
|
||||
}
|
||||
)
|
||||
|
||||
func newFsStandardLogoModel(conn sqlx.SqlConn) *defaultFsStandardLogoModel {
|
||||
return &defaultFsStandardLogoModel{
|
||||
conn: conn,
|
||||
table: "`fs_standard_logo`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultFsStandardLogoModel) 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 *defaultFsStandardLogoModel) FindOne(ctx context.Context, id int64) (*FsStandardLogo, error) {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsStandardLogoRows, m.table)
|
||||
var resp FsStandardLogo
|
||||
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 *defaultFsStandardLogoModel) Insert(ctx context.Context, data *FsStandardLogo) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?)", m.table, fsStandardLogoRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.Name, data.Image, data.Ctime, data.Status)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultFsStandardLogoModel) Update(ctx context.Context, data *FsStandardLogo) error {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsStandardLogoRowsWithPlaceHolder)
|
||||
_, err := m.conn.ExecCtx(ctx, query, data.Name, data.Image, data.Ctime, data.Status, data.Id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultFsStandardLogoModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
Reference in New Issue
Block a user