Repository navigation
Expand file tree
/
Copy pathquery.sql.go
More file actions
123 lines (110 loc) · 2.52 KB
/
Copy pathquery.sql.go
File metadata and controls
123 lines (110 loc) · 2.52 KB
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
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: query.sql
package authors
import (
"context"
"database/sql"
"errors"
"iter"
)
const createAuthor = `-- name: CreateAuthor :execresult
INSERT INTO authors (
name, bio
) VALUES (
?, ?
)
`
type CreateAuthorParams struct {
Name string
Bio sql.NullString
}
func (q *Queries) CreateAuthor(ctx context.Context, arg CreateAuthorParams) (sql.Result, error) {
return q.db.ExecContext(ctx, createAuthor, arg.Name, arg.Bio)
}
const deleteAuthor = `-- name: DeleteAuthor :exec
DELETE FROM authors
WHERE id = ?
`
func (q *Queries) DeleteAuthor(ctx context.Context, id int64) error {
_, err := q.db.ExecContext(ctx, deleteAuthor, id)
return err
}
const getAuthor = `-- name: GetAuthor :one
SELECT id, name, bio FROM authors
WHERE id = ? LIMIT 1
`
func (q *Queries) GetAuthor(ctx context.Context, id int64) (Author, error) {
row := q.db.QueryRowContext(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
`
// IterAuthors returns a single-use iterator. The query runs when the
// iterator is ranged over, and the returned func reports its error
// after the loop.
func (q *Queries) IterAuthors(ctx context.Context) (iter.Seq[Author], func() error) {
var _err error
var _used bool
return func(_yield func(Author) bool) {
if _used {
_err = errors.New("query IterAuthors: iterator already used")
return
}
_used = true
rows, err := q.db.QueryContext(ctx, iterAuthors)
if err != nil {
_err = err
return
}
defer rows.Close()
for rows.Next() {
var i Author
if err := rows.Scan(&i.ID, &i.Name, &i.Bio); err != nil {
_err = err
return
}
if !_yield(i) {
break
}
}
if err := rows.Close(); err != nil {
_err = err
return
}
if err := rows.Err(); err != nil {
_err = err
}
}, func() error { return _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.QueryContext(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.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}