u
This commit is contained in:
1 parent
d51eacb8ad
commit
44b3ef27d2
50 files changed
+3141
-9734
No files matched your search
@@ -9,3 +9,33 @@ FROM money_record mr
|
||||
WHERE mr.user_id = $1
|
||||
AND mr.record_time BETWEEN $2 AND $3
|
||||
ORDER BY mr.record_time DESC, mr.create_time DESC;
|
||||
|
||||
-- name: InsertMoneyRecord :one
|
||||
INSERT INTO money_record (
|
||||
id,
|
||||
category_id,
|
||||
user_id,
|
||||
amount,
|
||||
remark,
|
||||
record_time
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5,$6
|
||||
)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetMoneyRecordById :one
|
||||
SELECT * FROM money_record WHERE id = $1;
|
||||
|
||||
-- name: UpdateMoneyRecord :exec
|
||||
UPDATE money_record
|
||||
SET
|
||||
category_id = $2,
|
||||
amount = $3,
|
||||
remark = $4,
|
||||
record_time = $5,
|
||||
update_time = NOW()
|
||||
WHERE id = $1
|
||||
RETURNING *;
|
||||
|
||||
-- name: DeleteMoneyRecord :exec
|
||||
DELETE FROM money_record WHERE id = $1;
|
||||
@@ -11,6 +11,15 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const deleteMoneyRecord = `-- name: DeleteMoneyRecord :exec
|
||||
DELETE FROM money_record WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteMoneyRecord(ctx context.Context, id int64) error {
|
||||
_, err := q.db.Exec(ctx, deleteMoneyRecord, id)
|
||||
return err
|
||||
}
|
||||
|
||||
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,
|
||||
@@ -75,3 +84,100 @@ func (q *Queries) FindUserMoneyRecords(ctx context.Context, arg FindUserMoneyRec
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getMoneyRecordById = `-- name: GetMoneyRecordById :one
|
||||
SELECT id, category_id, user_id, amount, remark, record_time, create_time, update_time FROM money_record WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetMoneyRecordById(ctx context.Context, id int64) (MoneyRecord, error) {
|
||||
row := q.db.QueryRow(ctx, getMoneyRecordById, id)
|
||||
var i MoneyRecord
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CategoryID,
|
||||
&i.UserID,
|
||||
&i.Amount,
|
||||
&i.Remark,
|
||||
&i.RecordTime,
|
||||
&i.CreateTime,
|
||||
&i.UpdateTime,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertMoneyRecord = `-- name: InsertMoneyRecord :one
|
||||
INSERT INTO money_record (
|
||||
id,
|
||||
category_id,
|
||||
user_id,
|
||||
amount,
|
||||
remark,
|
||||
record_time
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5,$6
|
||||
)
|
||||
RETURNING id, category_id, user_id, amount, remark, record_time, create_time, update_time
|
||||
`
|
||||
|
||||
type InsertMoneyRecordParams struct {
|
||||
ID int64
|
||||
CategoryID int64
|
||||
UserID int64
|
||||
Amount pgtype.Numeric
|
||||
Remark pgtype.Text
|
||||
RecordTime pgtype.Timestamp
|
||||
}
|
||||
|
||||
func (q *Queries) InsertMoneyRecord(ctx context.Context, arg InsertMoneyRecordParams) (MoneyRecord, error) {
|
||||
row := q.db.QueryRow(ctx, insertMoneyRecord,
|
||||
arg.ID,
|
||||
arg.CategoryID,
|
||||
arg.UserID,
|
||||
arg.Amount,
|
||||
arg.Remark,
|
||||
arg.RecordTime,
|
||||
)
|
||||
var i MoneyRecord
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CategoryID,
|
||||
&i.UserID,
|
||||
&i.Amount,
|
||||
&i.Remark,
|
||||
&i.RecordTime,
|
||||
&i.CreateTime,
|
||||
&i.UpdateTime,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateMoneyRecord = `-- name: UpdateMoneyRecord :exec
|
||||
UPDATE money_record
|
||||
SET
|
||||
category_id = $2,
|
||||
amount = $3,
|
||||
remark = $4,
|
||||
record_time = $5,
|
||||
update_time = NOW()
|
||||
WHERE id = $1
|
||||
RETURNING id, category_id, user_id, amount, remark, record_time, create_time, update_time
|
||||
`
|
||||
|
||||
type UpdateMoneyRecordParams struct {
|
||||
ID int64
|
||||
CategoryID int64
|
||||
Amount pgtype.Numeric
|
||||
Remark pgtype.Text
|
||||
RecordTime pgtype.Timestamp
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateMoneyRecord(ctx context.Context, arg UpdateMoneyRecordParams) error {
|
||||
_, err := q.db.Exec(ctx, updateMoneyRecord,
|
||||
arg.ID,
|
||||
arg.CategoryID,
|
||||
arg.Amount,
|
||||
arg.Remark,
|
||||
arg.RecordTime,
|
||||
)
|
||||
return err
|
||||
}
|
||||
@@ -39,4 +39,10 @@ CREATE TABLE money_user_category(
|
||||
type INT NOT NULL DEFAULT 0,
|
||||
sort_number INT NOT NULL DEFAULT 0,
|
||||
create_time timestamp DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE share_space(
|
||||
id BIGINT PRIMARY KEY,
|
||||
name VARCHAR(100) NOT NULL
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user