This commit is contained in:
oneao committed 2025-11-29 17:23:27 +08:00
1 parent 8408cf779f
commit 25a9e41025
58 files changed
+2079 -6308

No files matched your search

@@ -0,0 +1,47 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: copyfrom.go
package dbtype
import (
"context"
)
// iteratorForBatchInsertMoneyUserCategories implements pgx.CopyFromSource.
type iteratorForBatchInsertMoneyUserCategories struct {
rows []BatchInsertMoneyUserCategoriesParams
skippedFirstNextCall bool
}
func (r *iteratorForBatchInsertMoneyUserCategories) Next() bool {
if len(r.rows) == 0 {
return false
}
if !r.skippedFirstNextCall {
r.skippedFirstNextCall = true
return true
}
r.rows = r.rows[1:]
return len(r.rows) > 0
}
func (r iteratorForBatchInsertMoneyUserCategories) Values() ([]interface{}, error) {
return []interface{}{
r.rows[0].ID,
r.rows[0].UserID,
r.rows[0].Name,
r.rows[0].Icon,
r.rows[0].Type,
r.rows[0].SortNumber,
}, nil
}
func (r iteratorForBatchInsertMoneyUserCategories) Err() error {
return nil
}
func (q *Queries) BatchInsertMoneyUserCategories(ctx context.Context, arg []BatchInsertMoneyUserCategoriesParams) (int64, error) {
return q.db.CopyFrom(ctx, []string{"money_user_category"}, []string{"id", "user_id", "name", "icon", "type", "sort_number"}, &iteratorForBatchInsertMoneyUserCategories{rows: arg})
}
+2 -1
View File
@@ -2,7 +2,7 @@
// versions:
// sqlc v1.30.0
package sqlcg
package dbtype
import (
"context"
@@ -15,6 +15,7 @@ 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
CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)
}
func New(db DBTX) *Queries {
@@ -2,7 +2,7 @@
// versions:
// sqlc v1.30.0
package sqlcg
package dbtype
import (
"github.com/jackc/pgx/v5/pgtype"
@@ -23,7 +23,7 @@ type MoneySysCategory struct {
ID int64
Name string
Icon string
Type pgtype.Int2
Type pgtype.Int4
SortNumber pgtype.Int4
CreateTime pgtype.Timestamp
}
@@ -33,7 +33,7 @@ type MoneyUserCategory struct {
UserID int64
Name string
Icon string
Type pgtype.Int2
Type pgtype.Int4
SortNumber pgtype.Int4
CreateTime pgtype.Timestamp
}
@@ -0,0 +1,41 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: money_sys_category.sql
package dbtype
import (
"context"
)
const listMoneySysCategory = `-- name: ListMoneySysCategory :many
SELECT id, name, icon, type, sort_number, create_time FROM money_sys_category
`
func (q *Queries) ListMoneySysCategory(ctx context.Context) ([]MoneySysCategory, error) {
rows, err := q.db.Query(ctx, listMoneySysCategory)
if err != nil {
return nil, err
}
defer rows.Close()
var items []MoneySysCategory
for rows.Next() {
var i MoneySysCategory
if err := rows.Scan(
&i.ID,
&i.Name,
&i.Icon,
&i.Type,
&i.SortNumber,
&i.CreateTime,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
@@ -0,0 +1,55 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: money_user_category.sql
package dbtype
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
type BatchInsertMoneyUserCategoriesParams struct {
ID int64
UserID int64
Name string
Icon string
Type pgtype.Int4
SortNumber pgtype.Int4
}
const findUserMoneyCategoriesByUserID = `-- name: FindUserMoneyCategoriesByUserID :many
SELECT id, user_id, name, icon, type, sort_number, create_time
FROM money_user_category
WHERE user_id = $1
`
func (q *Queries) FindUserMoneyCategoriesByUserID(ctx context.Context, userID int64) ([]MoneyUserCategory, error) {
rows, err := q.db.Query(ctx, findUserMoneyCategoriesByUserID, userID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []MoneyUserCategory
for rows.Next() {
var i MoneyUserCategory
if err := rows.Scan(
&i.ID,
&i.UserID,
&i.Name,
&i.Icon,
&i.Type,
&i.SortNumber,
&i.CreateTime,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
@@ -3,47 +3,21 @@
// sqlc v1.30.0
// source: user_info.sql
package sqlcg
package dbtype
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
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
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)
// 根据账号查询单条用户记录
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,
@@ -85,13 +59,64 @@ func (q *Queries) GetUserById(ctx context.Context, id int64) (UserInfo, error) {
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 {