u
This commit is contained in:
1 parent
5308dc8fda
commit
d51eacb8ad
32 files changed
+1788
-513
No files matched your search
@@ -0,0 +1,68 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: batch.go
|
||||
|
||||
package repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrBatchAlreadyClosed = errors.New("batch already closed")
|
||||
)
|
||||
|
||||
const batchUpdateMoneyCategorySort = `-- name: BatchUpdateMoneyCategorySort :batchexec
|
||||
UPDATE money_user_category
|
||||
SET sort_number = $2
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
type BatchUpdateMoneyCategorySortBatchResults struct {
|
||||
br pgx.BatchResults
|
||||
tot int
|
||||
closed bool
|
||||
}
|
||||
|
||||
type BatchUpdateMoneyCategorySortParams struct {
|
||||
ID int64
|
||||
SortNumber int32
|
||||
}
|
||||
|
||||
func (q *Queries) BatchUpdateMoneyCategorySort(ctx context.Context, arg []BatchUpdateMoneyCategorySortParams) *BatchUpdateMoneyCategorySortBatchResults {
|
||||
batch := &pgx.Batch{}
|
||||
for _, a := range arg {
|
||||
vals := []interface{}{
|
||||
a.ID,
|
||||
a.SortNumber,
|
||||
}
|
||||
batch.Queue(batchUpdateMoneyCategorySort, vals...)
|
||||
}
|
||||
br := q.db.SendBatch(ctx, batch)
|
||||
return &BatchUpdateMoneyCategorySortBatchResults{br, len(arg), false}
|
||||
}
|
||||
|
||||
func (b *BatchUpdateMoneyCategorySortBatchResults) Exec(f func(int, error)) {
|
||||
defer b.br.Close()
|
||||
for t := 0; t < b.tot; t++ {
|
||||
if b.closed {
|
||||
if f != nil {
|
||||
f(t, ErrBatchAlreadyClosed)
|
||||
}
|
||||
continue
|
||||
}
|
||||
_, err := b.br.Exec()
|
||||
if f != nil {
|
||||
f(t, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BatchUpdateMoneyCategorySortBatchResults) Close() error {
|
||||
b.closed = true
|
||||
return b.br.Close()
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: copyfrom.go
|
||||
|
||||
package repo
|
||||
|
||||
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})
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package repo
|
||||
|
||||
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
|
||||
CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)
|
||||
SendBatch(context.Context, *pgx.Batch) pgx.BatchResults
|
||||
}
|
||||
|
||||
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 repo
|
||||
|
||||
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 int32
|
||||
SortNumber int32
|
||||
CreateTime pgtype.Timestamp
|
||||
}
|
||||
|
||||
type MoneyUserCategory struct {
|
||||
ID int64
|
||||
UserID int64
|
||||
Name string
|
||||
Icon string
|
||||
Type int32
|
||||
SortNumber int32
|
||||
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,77 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: money_record.sql
|
||||
|
||||
package repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const findUserMoneyRecords = `-- name: FindUserMoneyRecords :many
|
||||
SELECT
|
||||
mr.id, mr.category_id, mr.user_id, mr.amount, mr.remark, mr.record_time, mr.create_time, mr.update_time,
|
||||
muc.name AS category_name,
|
||||
muc.icon AS category_icon,
|
||||
muc.type AS category_type
|
||||
FROM money_record mr
|
||||
LEFT JOIN money_user_category muc ON mr.category_id = muc.id
|
||||
WHERE mr.user_id = $1
|
||||
AND mr.record_time BETWEEN $2 AND $3
|
||||
ORDER BY mr.record_time DESC, mr.create_time DESC
|
||||
`
|
||||
|
||||
type FindUserMoneyRecordsParams struct {
|
||||
UserID int64
|
||||
RecordTime pgtype.Timestamp
|
||||
RecordTime_2 pgtype.Timestamp
|
||||
}
|
||||
|
||||
type FindUserMoneyRecordsRow struct {
|
||||
ID int64
|
||||
CategoryID int64
|
||||
UserID int64
|
||||
Amount pgtype.Numeric
|
||||
Remark pgtype.Text
|
||||
RecordTime pgtype.Timestamp
|
||||
CreateTime pgtype.Timestamp
|
||||
UpdateTime pgtype.Timestamp
|
||||
CategoryName pgtype.Text
|
||||
CategoryIcon pgtype.Text
|
||||
CategoryType pgtype.Int4
|
||||
}
|
||||
|
||||
func (q *Queries) FindUserMoneyRecords(ctx context.Context, arg FindUserMoneyRecordsParams) ([]FindUserMoneyRecordsRow, error) {
|
||||
rows, err := q.db.Query(ctx, findUserMoneyRecords, arg.UserID, arg.RecordTime, arg.RecordTime_2)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []FindUserMoneyRecordsRow
|
||||
for rows.Next() {
|
||||
var i FindUserMoneyRecordsRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.CategoryID,
|
||||
&i.UserID,
|
||||
&i.Amount,
|
||||
&i.Remark,
|
||||
&i.RecordTime,
|
||||
&i.CreateTime,
|
||||
&i.UpdateTime,
|
||||
&i.CategoryName,
|
||||
&i.CategoryIcon,
|
||||
&i.CategoryType,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: money_sys_category.sql
|
||||
|
||||
package repo
|
||||
|
||||
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,63 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: money_user_category.sql
|
||||
|
||||
package repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type BatchInsertMoneyUserCategoriesParams struct {
|
||||
ID int64
|
||||
UserID int64
|
||||
Name string
|
||||
Icon string
|
||||
Type int32
|
||||
SortNumber int32
|
||||
}
|
||||
|
||||
const deleteUserMoneyCategoryById = `-- name: DeleteUserMoneyCategoryById :exec
|
||||
DELETE FROM money_user_category
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteUserMoneyCategoryById(ctx context.Context, id int64) error {
|
||||
_, err := q.db.Exec(ctx, deleteUserMoneyCategoryById, id)
|
||||
return err
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: user_info.sql
|
||||
|
||||
package repo
|
||||
|
||||
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
|
||||
}
|
||||
Reference in new issue
Block a user