91 lines
2.9 KiB
Go
91 lines
2.9 KiB
Go
|
// 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 (
|
|||
|
fsFaqFieldNames = builder.RawFieldNames(&FsFaq{})
|
|||
|
fsFaqRows = strings.Join(fsFaqFieldNames, ",")
|
|||
|
fsFaqRowsExpectAutoSet = strings.Join(stringx.Remove(fsFaqFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
|||
|
fsFaqRowsWithPlaceHolder = strings.Join(stringx.Remove(fsFaqFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
|||
|
)
|
|||
|
|
|||
|
type (
|
|||
|
fsFaqModel interface {
|
|||
|
Insert(ctx context.Context, data *FsFaq) (sql.Result, error)
|
|||
|
FindOne(ctx context.Context, id int64) (*FsFaq, error)
|
|||
|
Update(ctx context.Context, data *FsFaq) error
|
|||
|
Delete(ctx context.Context, id int64) error
|
|||
|
}
|
|||
|
|
|||
|
defaultFsFaqModel struct {
|
|||
|
conn sqlx.SqlConn
|
|||
|
table string
|
|||
|
}
|
|||
|
|
|||
|
FsFaq struct {
|
|||
|
Id int64 `db:"id"`
|
|||
|
TagId int64 `db:"tag_id"` // 分类ID
|
|||
|
TagName string `db:"tag_name"` // 分类名称
|
|||
|
Title string `db:"title"` // 标题
|
|||
|
Content sql.NullString `db:"content"` // 内容
|
|||
|
Status int64 `db:"status"` // 状态(0:禁用,1:启用)
|
|||
|
Sort int64 `db:"sort"` // 排序
|
|||
|
Ctime sql.NullInt64 `db:"ctime"` // 添加时间
|
|||
|
}
|
|||
|
)
|
|||
|
|
|||
|
func newFsFaqModel(conn sqlx.SqlConn) *defaultFsFaqModel {
|
|||
|
return &defaultFsFaqModel{
|
|||
|
conn: conn,
|
|||
|
table: "`fs_faq`",
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
func (m *defaultFsFaqModel) 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 *defaultFsFaqModel) FindOne(ctx context.Context, id int64) (*FsFaq, error) {
|
|||
|
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsFaqRows, m.table)
|
|||
|
var resp FsFaq
|
|||
|
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 *defaultFsFaqModel) Insert(ctx context.Context, data *FsFaq) (sql.Result, error) {
|
|||
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?)", m.table, fsFaqRowsExpectAutoSet)
|
|||
|
ret, err := m.conn.ExecCtx(ctx, query, data.TagId, data.TagName, data.Title, data.Content, data.Status, data.Sort, data.Ctime)
|
|||
|
return ret, err
|
|||
|
}
|
|||
|
|
|||
|
func (m *defaultFsFaqModel) Update(ctx context.Context, data *FsFaq) error {
|
|||
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsFaqRowsWithPlaceHolder)
|
|||
|
_, err := m.conn.ExecCtx(ctx, query, data.TagId, data.TagName, data.Title, data.Content, data.Status, data.Sort, data.Ctime, data.Id)
|
|||
|
return err
|
|||
|
}
|
|||
|
|
|||
|
func (m *defaultFsFaqModel) tableName() string {
|
|||
|
return m.table
|
|||
|
}
|