|
|
|
// Code generated by goctl. DO NOT EDIT!
|
|
|
|
|
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"database/sql"
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"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 (
|
|
|
|
userPlatformFieldNames = builder.RawFieldNames(&UserPlatform{})
|
|
|
|
userPlatformRows = strings.Join(userPlatformFieldNames, ",")
|
|
|
|
userPlatformRowsExpectAutoSet = strings.Join(stringx.Remove(userPlatformFieldNames, "`create_time`", "`update_time`"), ",")
|
|
|
|
userPlatformRowsWithPlaceHolder = strings.Join(stringx.Remove(userPlatformFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
userPlatformModel interface {
|
|
|
|
Insert(ctx context.Context, data *UserPlatform) (sql.Result, error)
|
|
|
|
FindOne(ctx context.Context, id int64) (*UserPlatform, error)
|
|
|
|
Update(ctx context.Context, data *UserPlatform) error
|
|
|
|
Delete(ctx context.Context, id int64) error
|
|
|
|
}
|
|
|
|
|
|
|
|
defaultUserPlatformModel struct {
|
|
|
|
conn sqlx.SqlConn
|
|
|
|
table string
|
|
|
|
}
|
|
|
|
|
|
|
|
UserPlatform struct {
|
|
|
|
Id int64 `db:"id"` // 主键
|
|
|
|
UserId int64 `db:"user_id"` // 用户ID
|
|
|
|
Platform string `db:"platform"` // 平台类型
|
|
|
|
POpenid string `db:"p_openid"` // 平台用户openid
|
|
|
|
PUid string `db:"p_uid"` // 平台用户uid
|
|
|
|
PUname string `db:"p_uname"` // 平台用户名
|
|
|
|
PInfo string `db:"p_info"` // 平台用户原始信息(json)
|
|
|
|
PAvatar string `db:"p_avatar"` // 平台用户头像地址
|
|
|
|
CreateTime time.Time `db:"create_time"` // 创建时间
|
|
|
|
UpdateTime time.Time `db:"update_time"` // 更新时间
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func newUserPlatformModel(conn sqlx.SqlConn) *defaultUserPlatformModel {
|
|
|
|
return &defaultUserPlatformModel{
|
|
|
|
conn: conn,
|
|
|
|
table: "`user_platform`",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *defaultUserPlatformModel) Insert(ctx context.Context, data *UserPlatform) (sql.Result, error) {
|
|
|
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?)", m.table, userPlatformRowsExpectAutoSet)
|
|
|
|
ret, err := m.conn.ExecCtx(ctx, query, data.Id, data.UserId, data.Platform, data.POpenid, data.PUid, data.PUname, data.PInfo, data.PAvatar)
|
|
|
|
return ret, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *defaultUserPlatformModel) FindOne(ctx context.Context, id int64) (*UserPlatform, error) {
|
|
|
|
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", userPlatformRows, m.table)
|
|
|
|
var resp UserPlatform
|
|
|
|
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 *defaultUserPlatformModel) Update(ctx context.Context, data *UserPlatform) error {
|
|
|
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, userPlatformRowsWithPlaceHolder)
|
|
|
|
_, err := m.conn.ExecCtx(ctx, query, data.UserId, data.Platform, data.POpenid, data.PUid, data.PUname, data.PInfo, data.PAvatar, data.Id)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *defaultUserPlatformModel) 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 *defaultUserPlatformModel) tableName() string {
|
|
|
|
return m.table
|
|
|
|
}
|