u
This commit is contained in:
1 parent
6277fb2f9e
commit
8ecac0d7dd
270 files changed
+40438
-529
No files matched your search
@@ -0,0 +1,146 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: user_info.sql
|
||||
|
||||
package repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const getUserByAccount = `-- name: GetUserByAccount :one
|
||||
SELECT id, seq_no, account, password, email, username, gender, create_time, update_time, active_time, last_login_time
|
||||
FROM user_info
|
||||
WHERE account = $1
|
||||
`
|
||||
|
||||
// 根据账号查询单条用户记录
|
||||
func (q *Queries) GetUserByAccount(ctx context.Context, account string) (UserInfo, error) {
|
||||
row := q.db.QueryRow(ctx, getUserByAccount, account)
|
||||
var i UserInfo
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.SeqNo,
|
||||
&i.Account,
|
||||
&i.Password,
|
||||
&i.Email,
|
||||
&i.Username,
|
||||
&i.Gender,
|
||||
&i.CreateTime,
|
||||
&i.UpdateTime,
|
||||
&i.ActiveTime,
|
||||
&i.LastLoginTime,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserById = `-- name: GetUserById :one
|
||||
SELECT id, seq_no, account, password, email, username, gender, create_time, update_time, active_time, last_login_time
|
||||
FROM user_info
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
// 根据 ID 查询单条用户记录
|
||||
func (q *Queries) GetUserById(ctx context.Context, id int64) (UserInfo, error) {
|
||||
row := q.db.QueryRow(ctx, getUserById, id)
|
||||
var i UserInfo
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.SeqNo,
|
||||
&i.Account,
|
||||
&i.Password,
|
||||
&i.Email,
|
||||
&i.Username,
|
||||
&i.Gender,
|
||||
&i.CreateTime,
|
||||
&i.UpdateTime,
|
||||
&i.ActiveTime,
|
||||
&i.LastLoginTime,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserForLogin = `-- name: GetUserForLogin :one
|
||||
SELECT id, seq_no, account, password, email, username, gender, create_time, update_time, active_time, last_login_time
|
||||
FROM user_info
|
||||
WHERE account = $1
|
||||
AND password = $2
|
||||
`
|
||||
|
||||
type GetUserForLoginParams struct {
|
||||
Account string
|
||||
Password string
|
||||
}
|
||||
|
||||
// 根据账号和密码查询单条用户记录(登录用)
|
||||
func (q *Queries) GetUserForLogin(ctx context.Context, arg GetUserForLoginParams) (UserInfo, error) {
|
||||
row := q.db.QueryRow(ctx, getUserForLogin, arg.Account, arg.Password)
|
||||
var i UserInfo
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.SeqNo,
|
||||
&i.Account,
|
||||
&i.Password,
|
||||
&i.Email,
|
||||
&i.Username,
|
||||
&i.Gender,
|
||||
&i.CreateTime,
|
||||
&i.UpdateTime,
|
||||
&i.ActiveTime,
|
||||
&i.LastLoginTime,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertUser = `-- name: InsertUser :execrows
|
||||
INSERT INTO user_info (id, account, password,username)
|
||||
VALUES ($1, $2, $3,$4)
|
||||
`
|
||||
|
||||
type InsertUserParams struct {
|
||||
ID int64
|
||||
Account string
|
||||
Password string
|
||||
Username pgtype.Text
|
||||
}
|
||||
|
||||
// 插入用户并返回刚创建的记录
|
||||
func (q *Queries) InsertUser(ctx context.Context, arg InsertUserParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, insertUser,
|
||||
arg.ID,
|
||||
arg.Account,
|
||||
arg.Password,
|
||||
arg.Username,
|
||||
)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const updateUserActiveTime = `-- name: UpdateUserActiveTime :exec
|
||||
UPDATE user_info
|
||||
SET active_time = now()
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
// 更新用户活跃时间
|
||||
func (q *Queries) UpdateUserActiveTime(ctx context.Context, id int64) error {
|
||||
_, err := q.db.Exec(ctx, updateUserActiveTime, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateUserLoginLastTime = `-- name: UpdateUserLoginLastTime :exec
|
||||
UPDATE user_info
|
||||
SET last_login_time = now()
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
// 更新用户最后登录时间,并返回更新后的记录
|
||||
func (q *Queries) UpdateUserLoginLastTime(ctx context.Context, id int64) error {
|
||||
_, err := q.db.Exec(ctx, updateUserLoginLastTime, id)
|
||||
return err
|
||||
}
|
||||
Reference in new issue
Block a user