Home

mint @c32dcc68dbf0cacc9e749a5916729b80e2717d1e - refs - log -
-
https://git.jolheiser.com/mint.git
Budget
mint / database / transactions.sql.go
- raw -
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.29.0
// source: transactions.sql

package database

import (
	"context"
	"time"
)

const createTransaction = `-- name: CreateTransaction :one
INSERT INTO transactions (
    title, amount, date, recurrance, week, is_income
) VALUES (
    ?, ?, ?, ?, ?, ?
)
RETURNING id, title, amount, date, recurrance, week, is_income
`

type CreateTransactionParams struct {
	Title      string
	Amount     int64
	Date       time.Time
	Recurrance string
	Week       int64
	IsIncome   bool
}

func (q *Queries) CreateTransaction(ctx context.Context, arg CreateTransactionParams) (Transaction, error) {
	row := q.db.QueryRowContext(ctx, createTransaction,
		arg.Title,
		arg.Amount,
		arg.Date,
		arg.Recurrance,
		arg.Week,
		arg.IsIncome,
	)
	var i Transaction
	err := row.Scan(
		&i.ID,
		&i.Title,
		&i.Amount,
		&i.Date,
		&i.Recurrance,
		&i.Week,
		&i.IsIncome,
	)
	return i, err
}

const deleteTransaction = `-- name: DeleteTransaction :exec
DELETE FROM transactions
WHERE id = ?
`

func (q *Queries) DeleteTransaction(ctx context.Context, id int64) error {
	_, err := q.db.ExecContext(ctx, deleteTransaction, id)
	return err
}

const getTransaction = `-- name: GetTransaction :one
SELECT id, title, amount, date, recurrance, week, is_income from transactions
WHERE id = ? LIMIT 1
`

func (q *Queries) GetTransaction(ctx context.Context, id int64) (Transaction, error) {
	row := q.db.QueryRowContext(ctx, getTransaction, id)
	var i Transaction
	err := row.Scan(
		&i.ID,
		&i.Title,
		&i.Amount,
		&i.Date,
		&i.Recurrance,
		&i.Week,
		&i.IsIncome,
	)
	return i, err
}

const listTransactions = `-- name: ListTransactions :many
SELECT id, title, amount, date, recurrance, week, is_income FROM transactions
WHERE date BETWEEN ? AND ?
`

type ListTransactionsParams struct {
	FromDate time.Time
	ToDate   time.Time
}

func (q *Queries) ListTransactions(ctx context.Context, arg ListTransactionsParams) ([]Transaction, error) {
	rows, err := q.db.QueryContext(ctx, listTransactions, arg.FromDate, arg.ToDate)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Transaction
	for rows.Next() {
		var i Transaction
		if err := rows.Scan(
			&i.ID,
			&i.Title,
			&i.Amount,
			&i.Date,
			&i.Recurrance,
			&i.Week,
			&i.IsIncome,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Close(); err != nil {
		return nil, err
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const updateTransaction = `-- name: UpdateTransaction :one
UPDATE transactions
SET title = ?, amount = ?, date = ?, recurrance = ?, week = ?, is_income = ?
WHERE id = ?
RETURNING id, title, amount, date, recurrance, week, is_income
`

type UpdateTransactionParams struct {
	Title      string
	Amount     int64
	Date       time.Time
	Recurrance string
	Week       int64
	IsIncome   bool
	ID         int64
}

func (q *Queries) UpdateTransaction(ctx context.Context, arg UpdateTransactionParams) (Transaction, error) {
	row := q.db.QueryRowContext(ctx, updateTransaction,
		arg.Title,
		arg.Amount,
		arg.Date,
		arg.Recurrance,
		arg.Week,
		arg.IsIncome,
		arg.ID,
	)
	var i Transaction
	err := row.Scan(
		&i.ID,
		&i.Title,
		&i.Amount,
		&i.Date,
		&i.Recurrance,
		&i.Week,
		&i.IsIncome,
	)
	return i, err
}