/
entry.sql.go
124 lines (109 loc) · 2.44 KB
/
entry.sql.go
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
// Code generated by sqlc. DO NOT EDIT.
// source: entry.sql
package db
import (
"context"
)
const createEntry = `-- name: CreateEntry :one
INSERT INTO entries (
account_id,
amount
) VALUES (
$1, $2
) RETURNING id, account_id, amount, created_at
`
type CreateEntryParams struct {
AccountID int64 `json:"account_id"`
Amount int64 `json:"amount"`
}
func (q *Queries) CreateEntry(ctx context.Context, arg CreateEntryParams) (Entry, error) {
row := q.db.QueryRowContext(ctx, createEntry, arg.AccountID, arg.Amount)
var i Entry
err := row.Scan(
&i.ID,
&i.AccountID,
&i.Amount,
&i.CreatedAt,
)
return i, err
}
const deleteEntry = `-- name: DeleteEntry :exec
DELETE FROM entries WHERE id = $1
`
func (q *Queries) DeleteEntry(ctx context.Context, id int64) error {
_, err := q.db.ExecContext(ctx, deleteEntry, id)
return err
}
const getEntry = `-- name: GetEntry :one
SELECT id, account_id, amount, created_at FROM entries
WHERE id = $1 LIMIT 1
`
func (q *Queries) GetEntry(ctx context.Context, id int64) (Entry, error) {
row := q.db.QueryRowContext(ctx, getEntry, id)
var i Entry
err := row.Scan(
&i.ID,
&i.AccountID,
&i.Amount,
&i.CreatedAt,
)
return i, err
}
const listEntries = `-- name: ListEntries :many
SELECT id, account_id, amount, created_at FROM entries
ORDER BY id
LIMIT $1
OFFSET $2
`
type ListEntriesParams struct {
Limit int32 `json:"limit"`
Offset int32 `json:"offset"`
}
func (q *Queries) ListEntries(ctx context.Context, arg ListEntriesParams) ([]Entry, error) {
rows, err := q.db.QueryContext(ctx, listEntries, arg.Limit, arg.Offset)
if err != nil {
return nil, err
}
defer rows.Close()
items := []Entry{}
for rows.Next() {
var i Entry
if err := rows.Scan(
&i.ID,
&i.AccountID,
&i.Amount,
&i.CreatedAt,
); 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 updateEntry = `-- name: UpdateEntry :one
UPDATE entries
SET amount = $2
WHERE id = $1
RETURNING id, account_id, amount, created_at
`
type UpdateEntryParams struct {
ID int64 `json:"id"`
Amount int64 `json:"amount"`
}
func (q *Queries) UpdateEntry(ctx context.Context, arg UpdateEntryParams) (Entry, error) {
row := q.db.QueryRowContext(ctx, updateEntry, arg.ID, arg.Amount)
var i Entry
err := row.Scan(
&i.ID,
&i.AccountID,
&i.Amount,
&i.CreatedAt,
)
return i, err
}