Files
workspace/code/base-project/base-go-v3/db/sqlc/user_info.sql.go
T
2025-11-28 17:31:58 +08:00

102 lines
2.3 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: user_info.sql
package sqlcg
import (
"context"
)
const createUser = `-- name: CreateUser :execrows
INSERT INTO user_info (id, account, password)
VALUES ($1, $2, $3)
`
type CreateUserParams struct {
ID int64
Account string
Password string
}
// 插入用户并返回刚创建的记录
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (int64, error) {
result, err := q.db.Exec(ctx, createUser, arg.ID, arg.Account, arg.Password)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const getUserByAccountAndPassword = `-- name: GetUserByAccountAndPassword :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 GetUserByAccountAndPasswordParams struct {
Account string
Password string
}
// 根据账号和密码查询单条用户记录(登录用)
func (q *Queries) GetUserByAccountAndPassword(ctx context.Context, arg GetUserByAccountAndPasswordParams) (UserInfo, error) {
row := q.db.QueryRow(ctx, getUserByAccountAndPassword, 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 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 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
}