95 lines
3.4 KiB
Go
Executable File
95 lines
3.4 KiB
Go
Executable File
// Code generated by goctl. DO NOT EDIT.
|
||
// versions:
|
||
// goctl version: 1.7.3
|
||
|
||
package model
|
||
|
||
import (
|
||
"context"
|
||
"database/sql"
|
||
"fmt"
|
||
"strings"
|
||
"time"
|
||
|
||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||
"github.com/zeromicro/go-zero/core/stringx"
|
||
)
|
||
|
||
var (
|
||
nhTaskCommunityFieldNames = builder.RawFieldNames(&NhTaskCommunity{})
|
||
nhTaskCommunityRows = strings.Join(nhTaskCommunityFieldNames, ",")
|
||
nhTaskCommunityRowsExpectAutoSet = strings.Join(stringx.Remove(nhTaskCommunityFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||
nhTaskCommunityRowsWithPlaceHolder = strings.Join(stringx.Remove(nhTaskCommunityFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||
)
|
||
|
||
type (
|
||
nhTaskCommunityModel interface {
|
||
Insert(ctx context.Context, data *NhTaskCommunity) (sql.Result, error)
|
||
FindOne(ctx context.Context, id uint) (*NhTaskCommunity, error)
|
||
Update(ctx context.Context, data *NhTaskCommunity) error
|
||
Delete(ctx context.Context, id uint) error
|
||
}
|
||
|
||
defaultNhTaskCommunityModel struct {
|
||
conn sqlx.SqlConn
|
||
table string
|
||
}
|
||
|
||
NhTaskCommunity struct {
|
||
Id uint `db:"id"`
|
||
Title string `db:"title"` // 社区
|
||
Logo string `db:"logo"` // logo图片链接
|
||
Description string `db:"description"` // 描述
|
||
Status int8 `db:"status"` // 0=不启用,1=启用
|
||
StartAt sql.NullTime `db:"start_at"` // 开始时间
|
||
EndAt sql.NullTime `db:"end_at"` // 结束时间
|
||
CreatedAt time.Time `db:"created_at"` // 创建时间
|
||
UpdatedAt time.Time `db:"updated_at"` // 修改时间
|
||
Sort int `db:"sort"` // 数字越小越靠前
|
||
}
|
||
)
|
||
|
||
func newNhTaskCommunityModel(conn sqlx.SqlConn) *defaultNhTaskCommunityModel {
|
||
return &defaultNhTaskCommunityModel{
|
||
conn: conn,
|
||
table: "`nh_task_community`",
|
||
}
|
||
}
|
||
|
||
func (m *defaultNhTaskCommunityModel) Delete(ctx context.Context, id uint) error {
|
||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||
_, err := m.conn.ExecCtx(ctx, query, id)
|
||
return err
|
||
}
|
||
|
||
func (m *defaultNhTaskCommunityModel) FindOne(ctx context.Context, id uint) (*NhTaskCommunity, error) {
|
||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", nhTaskCommunityRows, m.table)
|
||
var resp NhTaskCommunity
|
||
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
|
||
switch err {
|
||
case nil:
|
||
return &resp, nil
|
||
case sqlx.ErrNotFound:
|
||
return nil, ErrNotFound
|
||
default:
|
||
return nil, err
|
||
}
|
||
}
|
||
|
||
func (m *defaultNhTaskCommunityModel) Insert(ctx context.Context, data *NhTaskCommunity) (sql.Result, error) {
|
||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?)", m.table, nhTaskCommunityRowsExpectAutoSet)
|
||
ret, err := m.conn.ExecCtx(ctx, query, data.Title, data.Logo, data.Description, data.Status, data.StartAt, data.EndAt, data.Sort)
|
||
return ret, err
|
||
}
|
||
|
||
func (m *defaultNhTaskCommunityModel) Update(ctx context.Context, data *NhTaskCommunity) error {
|
||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhTaskCommunityRowsWithPlaceHolder)
|
||
_, err := m.conn.ExecCtx(ctx, query, data.Title, data.Logo, data.Description, data.Status, data.StartAt, data.EndAt, data.Sort, data.Id)
|
||
return err
|
||
}
|
||
|
||
func (m *defaultNhTaskCommunityModel) tableName() string {
|
||
return m.table
|
||
}
|