Files
workspace/code/base-project/base-go-v3/db/sqlc/user_info.sql.go
T
2025-11-29 17:23:27 +08:00

127 lines
2.8 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: user_info.sql
package dbtype
import (
"context"
)
const getUserByAccount = `-- name: GetUserByAccount :one
SELECT id, seq_no, account, password, email, username, gender, create_time, update_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.LastLoginTime,
)
return i, err
}
const getUserById = `-- name: GetUserById :one
SELECT id, seq_no, account, password, email, username, gender, create_time, update_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.LastLoginTime,
)
return i, err
}
const getUserForLogin = `-- name: GetUserForLogin :one
SELECT id, seq_no, account, password, email, username, gender, create_time, update_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.LastLoginTime,
)
return i, err
}
const insertUser = `-- name: InsertUser :execrows
INSERT INTO user_info (id, account, password)
VALUES ($1, $2, $3)
`
type InsertUserParams struct {
ID int64
Account string
Password string
}
// 插入用户并返回刚创建的记录
func (q *Queries) InsertUser(ctx context.Context, arg InsertUserParams) (int64, error) {
result, err := q.db.Exec(ctx, insertUser, arg.ID, arg.Account, arg.Password)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const updateUserLoginLastTime = `-- name: UpdateUserLoginLastTime :execrows
UPDATE user_info
SET last_login_time = now()
WHERE id = $1
`
// 更新用户最后登录时间,并返回更新后的记录
func (q *Queries) UpdateUserLoginLastTime(ctx context.Context, id int64) (int64, error) {
result, err := q.db.Exec(ctx, updateUserLoginLastTime, id)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}