finish: gorm序列化
This commit is contained in:
24
model/fsguestmodel.go
Executable file
24
model/fsguestmodel.go
Executable file
@@ -0,0 +1,24 @@
|
||||
package model
|
||||
|
||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
|
||||
var _ FsGuestModel = (*customFsGuestModel)(nil)
|
||||
|
||||
type (
|
||||
// FsGuestModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customFsGuestModel.
|
||||
FsGuestModel interface {
|
||||
fsGuestModel
|
||||
}
|
||||
|
||||
customFsGuestModel struct {
|
||||
*defaultFsGuestModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewFsGuestModel returns a model for the database table.
|
||||
func NewFsGuestModel(conn sqlx.SqlConn) FsGuestModel {
|
||||
return &customFsGuestModel{
|
||||
defaultFsGuestModel: newFsGuestModel(conn),
|
||||
}
|
||||
}
|
||||
92
model/fsguestmodel_gen.go
Executable file
92
model/fsguestmodel_gen.go
Executable file
@@ -0,0 +1,92 @@
|
||||
// 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 (
|
||||
fsGuestFieldNames = builder.RawFieldNames(&FsGuest{})
|
||||
fsGuestRows = strings.Join(fsGuestFieldNames, ",")
|
||||
fsGuestRowsExpectAutoSet = strings.Join(stringx.Remove(fsGuestFieldNames, "`guest_id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
fsGuestRowsWithPlaceHolder = strings.Join(stringx.Remove(fsGuestFieldNames, "`guest_id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
)
|
||||
|
||||
type (
|
||||
fsGuestModel interface {
|
||||
Insert(ctx context.Context, data *FsGuest) (sql.Result, error)
|
||||
FindOne(ctx context.Context, guestId int64) (*FsGuest, error)
|
||||
Update(ctx context.Context, data *FsGuest) error
|
||||
Delete(ctx context.Context, guestId int64) error
|
||||
}
|
||||
|
||||
defaultFsGuestModel struct {
|
||||
conn sqlx.SqlConn
|
||||
table string
|
||||
}
|
||||
|
||||
FsGuest struct {
|
||||
GuestId int64 `db:"guest_id"` // 游客ID
|
||||
AuthKey string `db:"auth_key"` // jwt token
|
||||
Status int64 `db:"status"` // 1正常 0不正常
|
||||
IsDel int64 `db:"is_del"` // 是否删除 1删除
|
||||
CreatedAt int64 `db:"created_at"` // 添加时间
|
||||
UpdatedAt int64 `db:"updated_at"` // 更新时间
|
||||
IsOpenRender int64 `db:"is_open_render"` // 是否打开个性化渲染(1:开启,0:关闭)
|
||||
IsThousandFace int64 `db:"is_thousand_face"` // 是否已经存在千人千面(1:存在,0:不存在)
|
||||
IsLowRendering int64 `db:"is_low_rendering"` // 是否开启低渲染模型渲染
|
||||
IsRemoveBg int64 `db:"is_remove_bg"` // 用户上传logo是否去除背景
|
||||
}
|
||||
)
|
||||
|
||||
func newFsGuestModel(conn sqlx.SqlConn) *defaultFsGuestModel {
|
||||
return &defaultFsGuestModel{
|
||||
conn: conn,
|
||||
table: "`fs_guest`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultFsGuestModel) Delete(ctx context.Context, guestId int64) error {
|
||||
query := fmt.Sprintf("delete from %s where `guest_id` = ?", m.table)
|
||||
_, err := m.conn.ExecCtx(ctx, query, guestId)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultFsGuestModel) FindOne(ctx context.Context, guestId int64) (*FsGuest, error) {
|
||||
query := fmt.Sprintf("select %s from %s where `guest_id` = ? limit 1", fsGuestRows, m.table)
|
||||
var resp FsGuest
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, guestId)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultFsGuestModel) Insert(ctx context.Context, data *FsGuest) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?)", m.table, fsGuestRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.AuthKey, data.Status, data.IsDel, data.IsOpenRender, data.IsThousandFace, data.IsLowRendering, data.IsRemoveBg)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultFsGuestModel) Update(ctx context.Context, data *FsGuest) error {
|
||||
query := fmt.Sprintf("update %s set %s where `guest_id` = ?", m.table, fsGuestRowsWithPlaceHolder)
|
||||
_, err := m.conn.ExecCtx(ctx, query, data.AuthKey, data.Status, data.IsDel, data.IsOpenRender, data.IsThousandFace, data.IsLowRendering, data.IsRemoveBg, data.GuestId)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultFsGuestModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
14
model/gmodel/fsguestmodel.go
Executable file
14
model/gmodel/fsguestmodel.go
Executable file
@@ -0,0 +1,14 @@
|
||||
package gmodel
|
||||
|
||||
type FsGuest struct {
|
||||
GuestId int64 `gorm:"" json:"guest_id"` // ID
|
||||
AuthKey *string `gorm: json:"auth_key"` // jwt token
|
||||
Status *int64 `gorm: json:"status"` // 1正常 0不正常
|
||||
IsDel *int64 `gorm: json:"is_del"` // 是否删除 1删除
|
||||
CreatedAt *int64 `gorm: json:"created_at"` // 添加时间
|
||||
UpdatedAt *int64 `gorm: json:"updated_at"` // 更新时间
|
||||
IsOpenRender *int64 `gorm: json:"is_open_render"` // 是否打开个性化渲染(1:开启,0:关闭)
|
||||
IsThousandFace *int64 `gorm: json:"is_thousand_face"` // 是否已经存在千人千面(1:存在,0:不存在)
|
||||
IsLowRendering *int64 `gorm: json:"is_low_rendering"` // 是否开启低渲染模型渲染
|
||||
IsRemoveBg *int64 `gorm: json:"is_remove_bg"` // 用户上传logo是否去除背景
|
||||
}
|
||||
19
model/gmodel_gen/fs_guest_gen.go
Normal file
19
model/gmodel_gen/fs_guest_gen.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package model
|
||||
|
||||
import "gorm.io/gorm"
|
||||
|
||||
type FsGuest struct {
|
||||
GuestId int64 `gorm:"primary_key" json:"guest_id"` // 游客ID
|
||||
AuthKey *string `gorm:"" json:"auth_key"` // jwt token
|
||||
Status *int64 `gorm:"" json:"status"` // 1正常 0不正常
|
||||
IsDel *int64 `gorm:"" json:"is_del"` // 是否删除 1删除
|
||||
CreatedAt *int64 `gorm:"" json:"created_at"` // 添加时间
|
||||
UpdatedAt *int64 `gorm:"" json:"updated_at"` // 更新时间
|
||||
IsOpenRender *int64 `gorm:"" json:"is_open_render"` // 是否打开个性化渲染(1:开启,0:关闭)
|
||||
IsThousandFace *int64 `gorm:"" json:"is_thousand_face"` // 是否已经存在千人千面(1:存在,0:不存在)
|
||||
IsLowRendering *int64 `gorm:"" json:"is_low_rendering"` // 是否开启低渲染模型渲染
|
||||
IsRemoveBg *int64 `gorm:"" json:"is_remove_bg"` // 用户上传logo是否去除背景
|
||||
}
|
||||
type FsGuestModel struct{ db *gorm.DB }
|
||||
|
||||
func NewFsGuestModel(db *gorm.DB) *FsGuestModel { return &FsGuestModel{db} }
|
||||
Reference in New Issue
Block a user