-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathquery.sql.go
More file actions
122 lines (105 loc) · 2.8 KB
/
query.sql.go
File metadata and controls
122 lines (105 loc) · 2.8 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
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.28.0
// source: query.sql
package authors
import (
"context"
"fmt"
"github.com/jackc/pgx/v5/pgconn"
"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)
if err != nil {
err = fmt.Errorf("query CreateAuthor: %w", err)
}
return i, err
}
const deleteAuthorExec = `-- name: DeleteAuthorExec :exec
DELETE FROM authors
WHERE id = $1
`
func (q *Queries) DeleteAuthorExec(ctx context.Context, id int64) error {
_, err := q.db.Exec(ctx, deleteAuthorExec, id)
if err != nil {
return fmt.Errorf("query DeleteAuthorExec: %w", err)
}
return nil
}
const deleteAuthorExecLastID = `-- name: DeleteAuthorExecLastID :execlastid
DELETE FROM authors
WHERE id = $1
`
const deleteAuthorExecResult = `-- name: DeleteAuthorExecResult :execresult
DELETE FROM authors
WHERE id = $1
`
func (q *Queries) DeleteAuthorExecResult(ctx context.Context, id int64) (pgconn.CommandTag, error) {
result, err := q.db.Exec(ctx, deleteAuthorExecResult, id)
if err != nil {
err = fmt.Errorf("query DeleteAuthorExecResult: %w", err)
}
return result, err
}
const deleteAuthorExecRows = `-- name: DeleteAuthorExecRows :execrows
DELETE FROM authors
WHERE id = $1
`
func (q *Queries) DeleteAuthorExecRows(ctx context.Context, id int64) (int64, error) {
result, err := q.db.Exec(ctx, deleteAuthorExecRows, id)
if err != nil {
return 0, fmt.Errorf("query DeleteAuthorExecRows: %w", err)
}
return result.RowsAffected(), nil
}
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)
if err != nil {
err = fmt.Errorf("query GetAuthor: %w", err)
}
return i, 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, fmt.Errorf("query ListAuthors: %w", 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, fmt.Errorf("query ListAuthors: %w", err)
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, fmt.Errorf("query ListAuthors: %w", err)
}
return items, nil
}