-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathquery.sql.go
More file actions
80 lines (67 loc) · 1.71 KB
/
query.sql.go
File metadata and controls
80 lines (67 loc) · 1.71 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
// Code generated by sqlc. DO NOT EDIT.
// source: query.sql
package querytest
import (
"context"
"database/sql"
"github.com/jackc/pgconn"
)
const execFoo = `-- name: ExecFoo :exec
INSERT INTO foo (bar) VALUES ("bar")
`
// This function creates a Foo via :exec
func (q *Queries) ExecFoo(ctx context.Context) error {
_, err := q.db.Exec(ctx, execFoo)
return err
}
const execResultFoo = `-- name: ExecResultFoo :execresult
INSERT INTO foo (bar) VALUES ("bar")
`
// This function creates a Foo via :execresult
func (q *Queries) ExecResultFoo(ctx context.Context) (pgconn.CommandTag, error) {
return q.db.Exec(ctx, execResultFoo)
}
const execRowFoo = `-- name: ExecRowFoo :execrows
INSERT INTO foo (bar) VALUES ("bar")
`
// This function creates a Foo via :execrows
func (q *Queries) ExecRowFoo(ctx context.Context) (int64, error) {
result, err := q.db.Exec(ctx, execRowFoo)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const manyFoo = `-- name: ManyFoo :many
SELECT bar FROM foo
`
// This function returns a list of Foos
func (q *Queries) ManyFoo(ctx context.Context) ([]sql.NullString, error) {
rows, err := q.db.Query(ctx, manyFoo)
if err != nil {
return nil, err
}
defer rows.Close()
var items []sql.NullString
for rows.Next() {
var bar sql.NullString
if err := rows.Scan(&bar); err != nil {
return nil, err
}
items = append(items, bar)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const oneFoo = `-- name: OneFoo :one
SELECT bar FROM foo
`
// This function returns one Foo
func (q *Queries) OneFoo(ctx context.Context) (sql.NullString, error) {
row := q.db.QueryRow(ctx, oneFoo)
var bar sql.NullString
err := row.Scan(&bar)
return bar, err
}