122 lines
3.8 KiB
Go
Executable File
122 lines
3.8 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 (
|
|
nhTwitterFieldNames = builder.RawFieldNames(&NhTwitter{})
|
|
nhTwitterRows = strings.Join(nhTwitterFieldNames, ",")
|
|
nhTwitterRowsExpectAutoSet = strings.Join(stringx.Remove(nhTwitterFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
|
nhTwitterRowsWithPlaceHolder = strings.Join(stringx.Remove(nhTwitterFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
|
)
|
|
|
|
type (
|
|
nhTwitterModel interface {
|
|
Insert(ctx context.Context, data *NhTwitter) (sql.Result, error)
|
|
FindOne(ctx context.Context, id uint) (*NhTwitter, error)
|
|
FindOneByTwitterId(ctx context.Context, twitterId string) (*NhTwitter, error)
|
|
FindOneByUid(ctx context.Context, uid uint) (*NhTwitter, error)
|
|
Update(ctx context.Context, data *NhTwitter) error
|
|
Delete(ctx context.Context, id uint) error
|
|
}
|
|
|
|
defaultNhTwitterModel struct {
|
|
conn sqlx.SqlConn
|
|
table string
|
|
}
|
|
|
|
NhTwitter struct {
|
|
Id uint `db:"id"`
|
|
Uid uint `db:"uid"` // 用户ID
|
|
TwitterId string `db:"twitter_id"` // twitter_id
|
|
Name string `db:"name"` // name
|
|
Username string `db:"username"` // username
|
|
CreatedAt time.Time `db:"created_at"` // 创建时间
|
|
UpdatedAt time.Time `db:"updated_at"` // 修改时间
|
|
}
|
|
)
|
|
|
|
func newNhTwitterModel(conn sqlx.SqlConn) *defaultNhTwitterModel {
|
|
return &defaultNhTwitterModel{
|
|
conn: conn,
|
|
table: "`nh_twitter`",
|
|
}
|
|
}
|
|
|
|
func (m *defaultNhTwitterModel) 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 *defaultNhTwitterModel) FindOne(ctx context.Context, id uint) (*NhTwitter, error) {
|
|
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", nhTwitterRows, m.table)
|
|
var resp NhTwitter
|
|
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 *defaultNhTwitterModel) FindOneByTwitterId(ctx context.Context, twitterId string) (*NhTwitter, error) {
|
|
var resp NhTwitter
|
|
query := fmt.Sprintf("select %s from %s where `twitter_id` = ? limit 1", nhTwitterRows, m.table)
|
|
err := m.conn.QueryRowCtx(ctx, &resp, query, twitterId)
|
|
switch err {
|
|
case nil:
|
|
return &resp, nil
|
|
case sqlx.ErrNotFound:
|
|
return nil, ErrNotFound
|
|
default:
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
func (m *defaultNhTwitterModel) FindOneByUid(ctx context.Context, uid uint) (*NhTwitter, error) {
|
|
var resp NhTwitter
|
|
query := fmt.Sprintf("select %s from %s where `uid` = ? limit 1", nhTwitterRows, m.table)
|
|
err := m.conn.QueryRowCtx(ctx, &resp, query, uid)
|
|
switch err {
|
|
case nil:
|
|
return &resp, nil
|
|
case sqlx.ErrNotFound:
|
|
return nil, ErrNotFound
|
|
default:
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
func (m *defaultNhTwitterModel) Insert(ctx context.Context, data *NhTwitter) (sql.Result, error) {
|
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?)", m.table, nhTwitterRowsExpectAutoSet)
|
|
ret, err := m.conn.ExecCtx(ctx, query, data.Uid, data.TwitterId, data.Name, data.Username)
|
|
return ret, err
|
|
}
|
|
|
|
func (m *defaultNhTwitterModel) Update(ctx context.Context, newData *NhTwitter) error {
|
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhTwitterRowsWithPlaceHolder)
|
|
_, err := m.conn.ExecCtx(ctx, query, newData.Uid, newData.TwitterId, newData.Name, newData.Username, newData.Id)
|
|
return err
|
|
}
|
|
|
|
func (m *defaultNhTwitterModel) tableName() string {
|
|
return m.table
|
|
}
|