fusenapi/model/fsfontmodel_gen.go
laodaming 9a2f74fe64 fix
2023-06-06 17:36:11 +08:00

88 lines
2.8 KiB
Go
Executable File

// 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 (
fsFontFieldNames = builder.RawFieldNames(&FsFont{})
fsFontRows = strings.Join(fsFontFieldNames, ",")
fsFontRowsExpectAutoSet = strings.Join(stringx.Remove(fsFontFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
fsFontRowsWithPlaceHolder = strings.Join(stringx.Remove(fsFontFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)
type (
fsFontModel interface {
Insert(ctx context.Context, data *FsFont) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*FsFont, error)
Update(ctx context.Context, data *FsFont) error
Delete(ctx context.Context, id int64) error
}
defaultFsFontModel struct {
conn sqlx.SqlConn
table string
}
FsFont struct {
Id int64 `db:"id"` // id
Title string `db:"title"` // 字体名字
LinuxFontname string `db:"linux_fontname"` // linux对应字体名
FilePath string `db:"file_path"` // 字体文件路径
Sort int64 `db:"sort"` // 排序
}
)
func newFsFontModel(conn sqlx.SqlConn) *defaultFsFontModel {
return &defaultFsFontModel{
conn: conn,
table: "`fs_font`",
}
}
func (m *defaultFsFontModel) 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 *defaultFsFontModel) FindOne(ctx context.Context, id int64) (*FsFont, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsFontRows, m.table)
var resp FsFont
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 *defaultFsFontModel) Insert(ctx context.Context, data *FsFont) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?)", m.table, fsFontRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.Title, data.LinuxFontname, data.FilePath, data.Sort)
return ret, err
}
func (m *defaultFsFontModel) Update(ctx context.Context, data *FsFont) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsFontRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, data.Title, data.LinuxFontname, data.FilePath, data.Sort, data.Id)
return err
}
func (m *defaultFsFontModel) tableName() string {
return m.table
}