forked from sqlc-dev/sqlc
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquery.sql.go
More file actions
136 lines (124 loc) · 2.67 KB
/
query.sql.go
File metadata and controls
136 lines (124 loc) · 2.67 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
124
125
126
127
128
129
130
131
132
133
134
135
136
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.26.0
// source: query.sql
package querytest
import (
"context"
"database/sql"
)
const aliasExpand = `-- name: AliasExpand :many
SELECT f.id, b.id, title
FROM foo f
JOIN bar b ON b.id = f.id
WHERE f.id = ?
`
type AliasExpandRow struct {
ID uint64
ID_2 uint64
Title sql.NullString
}
func (q *Queries) AliasExpand(ctx context.Context, id uint64) ([]AliasExpandRow, error) {
rows, err := q.db.QueryContext(ctx, aliasExpand, id)
if err != nil {
return nil, err
}
defer rows.Close()
var items []AliasExpandRow
for rows.Next() {
var i AliasExpandRow
if err := rows.Scan(&i.ID, &i.ID_2, &i.Title); 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
}
const aliasJoin = `-- name: AliasJoin :many
SELECT f.id, b.title
FROM foo f
JOIN bar b ON b.id = f.id
WHERE f.id = ?
`
type AliasJoinRow struct {
ID uint64
Title sql.NullString
}
func (q *Queries) AliasJoin(ctx context.Context, id uint64) ([]AliasJoinRow, error) {
rows, err := q.db.QueryContext(ctx, aliasJoin, id)
if err != nil {
return nil, err
}
defer rows.Close()
var items []AliasJoinRow
for rows.Next() {
var i AliasJoinRow
if err := rows.Scan(&i.ID, &i.Title); 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
}
const columnAlias = `-- name: ColumnAlias :many
SELECT n FROM (SELECT 1 AS n) AS x WHERE n <= ?
`
func (q *Queries) ColumnAlias(ctx context.Context, n int32) ([]int32, error) {
rows, err := q.db.QueryContext(ctx, columnAlias, n)
if err != nil {
return nil, err
}
defer rows.Close()
var items []int32
for rows.Next() {
var n int32
if err := rows.Scan(&n); err != nil {
return nil, err
}
items = append(items, n)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const subqueryAlias = `-- name: SubqueryAlias :many
SELECT n FROM (SELECT 1 AS n) AS x WHERE x.n <= ?
`
func (q *Queries) SubqueryAlias(ctx context.Context, n int32) ([]int32, error) {
rows, err := q.db.QueryContext(ctx, subqueryAlias, n)
if err != nil {
return nil, err
}
defer rows.Close()
var items []int32
for rows.Next() {
var n int32
if err := rows.Scan(&n); err != nil {
return nil, err
}
items = append(items, n)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}