/
transfer.sql.go
108 lines (98 loc) · 2.13 KB
/
transfer.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
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.18.0
// source: transfer.sql
package db
import (
"context"
)
const createTransfer = `-- name: CreateTransfer :one
INSERT INTO transfers (
from_account_id,
to_account_id,
amount
) VALUES (
$1, $2, $3
) RETURNING id, from_account_id, to_account_id, amount, created_at
`
type CreateTransferParams struct {
FromAccountID int64
ToAccountID int64
Amount int64
}
func (q *Queries) CreateTransfer(ctx context.Context, arg CreateTransferParams) (Transfer, error) {
row := q.db.QueryRowContext(ctx, createTransfer, arg.FromAccountID, arg.ToAccountID, arg.Amount)
var i Transfer
err := row.Scan(
&i.ID,
&i.FromAccountID,
&i.ToAccountID,
&i.Amount,
&i.CreatedAt,
)
return i, err
}
const getTransfer = `-- name: GetTransfer :one
SELECT id, from_account_id, to_account_id, amount, created_at FROM transfers
WHERE id = $1 LIMIT 1
`
func (q *Queries) GetTransfer(ctx context.Context, id int64) (Transfer, error) {
row := q.db.QueryRowContext(ctx, getTransfer, id)
var i Transfer
err := row.Scan(
&i.ID,
&i.FromAccountID,
&i.ToAccountID,
&i.Amount,
&i.CreatedAt,
)
return i, err
}
const listTransfers = `-- name: ListTransfers :many
SELECT id, from_account_id, to_account_id, amount, created_at FROM transfers
WHERE
from_account_id = $1 OR
to_account_id = $2
ORDER BY id
LIMIT $3
OFFSET $4
`
type ListTransfersParams struct {
FromAccountID int64
ToAccountID int64
Limit int32
Offset int32
}
func (q *Queries) ListTransfers(ctx context.Context, arg ListTransfersParams) ([]Transfer, error) {
rows, err := q.db.QueryContext(ctx, listTransfers,
arg.FromAccountID,
arg.ToAccountID,
arg.Limit,
arg.Offset,
)
if err != nil {
return nil, err
}
defer rows.Close()
items := []Transfer{}
for rows.Next() {
var i Transfer
if err := rows.Scan(
&i.ID,
&i.FromAccountID,
&i.ToAccountID,
&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
}