90 lines
3.0 KiB
Go
90 lines
3.0 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 (
|
||
|
fsMapLibraryFieldNames = builder.RawFieldNames(&FsMapLibrary{})
|
||
|
fsMapLibraryRows = strings.Join(fsMapLibraryFieldNames, ",")
|
||
|
fsMapLibraryRowsExpectAutoSet = strings.Join(stringx.Remove(fsMapLibraryFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||
|
fsMapLibraryRowsWithPlaceHolder = strings.Join(stringx.Remove(fsMapLibraryFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||
|
)
|
||
|
|
||
|
type (
|
||
|
fsMapLibraryModel interface {
|
||
|
Insert(ctx context.Context, data *FsMapLibrary) (sql.Result, error)
|
||
|
FindOne(ctx context.Context, id int64) (*FsMapLibrary, error)
|
||
|
Update(ctx context.Context, data *FsMapLibrary) error
|
||
|
Delete(ctx context.Context, id int64) error
|
||
|
}
|
||
|
|
||
|
defaultFsMapLibraryModel struct {
|
||
|
conn sqlx.SqlConn
|
||
|
table string
|
||
|
}
|
||
|
|
||
|
FsMapLibrary struct {
|
||
|
Id int64 `db:"id"` // Id
|
||
|
Title string `db:"title"` // 名称
|
||
|
Info string `db:"info"` // 贴图数据
|
||
|
Sort int64 `db:"sort"` // 排序
|
||
|
Status int64 `db:"status"` // 状态 1启用
|
||
|
Ctime int64 `db:"ctime"` // 创建时间
|
||
|
TagId int64 `db:"tag_id"` // 模板标签id
|
||
|
}
|
||
|
)
|
||
|
|
||
|
func newFsMapLibraryModel(conn sqlx.SqlConn) *defaultFsMapLibraryModel {
|
||
|
return &defaultFsMapLibraryModel{
|
||
|
conn: conn,
|
||
|
table: "`fs_map_library`",
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (m *defaultFsMapLibraryModel) 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 *defaultFsMapLibraryModel) FindOne(ctx context.Context, id int64) (*FsMapLibrary, error) {
|
||
|
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsMapLibraryRows, m.table)
|
||
|
var resp FsMapLibrary
|
||
|
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 *defaultFsMapLibraryModel) Insert(ctx context.Context, data *FsMapLibrary) (sql.Result, error) {
|
||
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?)", m.table, fsMapLibraryRowsExpectAutoSet)
|
||
|
ret, err := m.conn.ExecCtx(ctx, query, data.Title, data.Info, data.Sort, data.Status, data.Ctime, data.TagId)
|
||
|
return ret, err
|
||
|
}
|
||
|
|
||
|
func (m *defaultFsMapLibraryModel) Update(ctx context.Context, data *FsMapLibrary) error {
|
||
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsMapLibraryRowsWithPlaceHolder)
|
||
|
_, err := m.conn.ExecCtx(ctx, query, data.Title, data.Info, data.Sort, data.Status, data.Ctime, data.TagId, data.Id)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
func (m *defaultFsMapLibraryModel) tableName() string {
|
||
|
return m.table
|
||
|
}
|