Implement assignment import and clear of budget
This commit is contained in:
54
postgres/assignments.sql.go
Normal file
54
postgres/assignments.sql.go
Normal file
@ -0,0 +1,54 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// source: assignments.sql
|
||||
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const createAssignment = `-- name: CreateAssignment :one
|
||||
INSERT INTO assignments (
|
||||
date, amount, category_id
|
||||
) VALUES (
|
||||
$1, $2, $3
|
||||
)
|
||||
RETURNING id, category_id, date, memo, amount
|
||||
`
|
||||
|
||||
type CreateAssignmentParams struct {
|
||||
Date time.Time
|
||||
Amount Numeric
|
||||
CategoryID uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) CreateAssignment(ctx context.Context, arg CreateAssignmentParams) (Assignment, error) {
|
||||
row := q.db.QueryRowContext(ctx, createAssignment, arg.Date, arg.Amount, arg.CategoryID)
|
||||
var i Assignment
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CategoryID,
|
||||
&i.Date,
|
||||
&i.Memo,
|
||||
&i.Amount,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteAllAssignments = `-- name: DeleteAllAssignments :execrows
|
||||
DELETE FROM assignments
|
||||
USING categories
|
||||
INNER JOIN category_groups ON categories.category_group_id = category_groups.id
|
||||
WHERE categories.id = assignments.category_id AND category_groups.budget_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteAllAssignments(ctx context.Context, budgetID uuid.UUID) (int64, error) {
|
||||
result, err := q.db.ExecContext(ctx, deleteAllAssignments, budgetID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected()
|
||||
}
|
Reference in New Issue
Block a user