Home

mint @f3cdde75f2c5333136ba1f0aeb7f88b271ba60a9 - 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
// 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
) VALUES (
    ?, ?, ?, ?
)
RETURNING id, title, amount, date, recurrance
`

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

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,
	)
	var i Transaction
	err := row.Scan(
		&i.ID,
		&i.Title,
		&i.Amount,
		&i.Date,
		&i.Recurrance,
	)
	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 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,
	)
	return i, err
}

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

type ListTransactionsParams struct {
	Date   time.Time
	Date_2 time.Time
}

func (q *Queries) ListTransactions(ctx context.Context, arg ListTransactionsParams) ([]Transaction, error) {
	rows, err := q.db.QueryContext(ctx, listTransactions, arg.Date, arg.Date_2)
	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,
		); 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 = ?
WHERE id = ?
RETURNING id, title, amount, date, recurrance
`

type UpdateTransactionParams struct {
	Title      string
	Amount     int64
	Date       time.Time
	Recurrance string
	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.ID,
	)
	var i Transaction
	err := row.Scan(
		&i.ID,
		&i.Title,
		&i.Amount,
		&i.Date,
		&i.Recurrance,
	)
	return i, err
}