-
Notifications
You must be signed in to change notification settings - Fork 864
/
Copy pathquery.sql.go
134 lines (113 loc) · 2.49 KB
/
query.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
125
126
127
128
129
130
131
132
133
134
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.27.0
// source: query.sql
package authors
import (
"context"
"iter"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
)
const createAuthor = `-- name: CreateAuthor :one
INSERT INTO authors (
name, bio
) VALUES (
$1, $2
)
RETURNING id, name, bio
`
type CreateAuthorParams struct {
Name string
Bio pgtype.Text
}
func (q *Queries) CreateAuthor(ctx context.Context, arg CreateAuthorParams) (Author, error) {
row := q.db.QueryRow(ctx, createAuthor, arg.Name, arg.Bio)
var i Author
err := row.Scan(&i.ID, &i.Name, &i.Bio)
return i, err
}
const deleteAuthor = `-- name: DeleteAuthor :exec
DELETE FROM authors
WHERE id = $1
`
func (q *Queries) DeleteAuthor(ctx context.Context, id int64) error {
_, err := q.db.Exec(ctx, deleteAuthor, id)
return err
}
const getAuthor = `-- name: GetAuthor :one
SELECT id, name, bio FROM authors
WHERE id = $1 LIMIT 1
`
func (q *Queries) GetAuthor(ctx context.Context, id int64) (Author, error) {
row := q.db.QueryRow(ctx, getAuthor, id)
var i Author
err := row.Scan(&i.ID, &i.Name, &i.Bio)
return i, err
}
const iterAuthors = `-- name: IterAuthors :iter
SELECT id, name, bio FROM authors
ORDER BY name
`
func (q *Queries) IterAuthors(ctx context.Context) IterAuthorsRows {
rows, err := q.db.Query(ctx, iterAuthors)
if err != nil {
return IterAuthorsRows{err: err}
}
return IterAuthorsRows{rows: rows}
}
type IterAuthorsRows struct {
rows pgx.Rows
err error
}
func (r *IterAuthorsRows) Iterate() iter.Seq[Author] {
if r.rows == nil {
return func(yield func(Author) bool) {}
}
return func(yield func(Author) bool) {
defer r.rows.Close()
for r.rows.Next() {
var i Author
err := r.rows.Scan(&i.ID, &i.Name, &i.Bio)
if err != nil {
r.err = err
return
}
if !yield(i) {
return
}
}
}
}
func (r *IterAuthorsRows) Close() {
r.rows.Close()
}
func (r *IterAuthorsRows) Err() error {
if r.err != nil {
return r.err
}
return r.rows.Err()
}
const listAuthors = `-- name: ListAuthors :many
SELECT id, name, bio FROM authors
ORDER BY name
`
func (q *Queries) ListAuthors(ctx context.Context) ([]Author, error) {
rows, err := q.db.Query(ctx, listAuthors)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Author
for rows.Next() {
var i Author
if err := rows.Scan(&i.ID, &i.Name, &i.Bio); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}