This commit is contained in:
oneao committed 2025-11-28 17:31:58 +08:00
1 parent d03ac2b00a
commit cf4291652a
43 files changed
+359 -6254

No files matched your search

@@ -0,0 +1,32 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
package sqlcg
import (
"context"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
)
type DBTX interface {
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
QueryRow(context.Context, string, ...interface{}) pgx.Row
}
func New(db DBTX) *Queries {
return &Queries{db: db}
}
type Queries struct {
db DBTX
}
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
return &Queries{
db: tx,
}
}
@@ -0,0 +1,52 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
package sqlcg
import (
"github.com/jackc/pgx/v5/pgtype"
)
type MoneyRecord struct {
ID int64
CategoryID int64
UserID int64
Amount pgtype.Numeric
Remark pgtype.Text
RecordTime pgtype.Timestamp
CreateTime pgtype.Timestamp
UpdateTime pgtype.Timestamp
}
type MoneySysCategory struct {
ID int64
Name string
Icon string
Type pgtype.Int2
SortNumber pgtype.Int4
CreateTime pgtype.Timestamp
}
type MoneyUserCategory struct {
ID int64
UserID int64
Name string
Icon string
Type pgtype.Int2
SortNumber pgtype.Int4
CreateTime pgtype.Timestamp
}
type UserInfo struct {
ID int64
SeqNo pgtype.Int4
Account string
Password string
Email pgtype.Text
Username pgtype.Text
Gender pgtype.Int4
CreateTime pgtype.Timestamp
UpdateTime pgtype.Timestamp
LastLoginTime pgtype.Timestamp
}
@@ -0,0 +1,101 @@
// 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
}