forked from sqlc-dev/sqlc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery.sql.go
More file actions
56 lines (51 loc) · 1.23 KB
/
query.sql.go
File metadata and controls
56 lines (51 loc) · 1.23 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
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.19.1
// source: query.sql
package querytest
import (
"context"
"strings"
)
const funcParamIdent = `-- name: FuncParamIdent :many
SELECT name FROM foo
WHERE name = ?1
AND id IN (/*SLICE:favourites*/?)
`
type FuncParamIdentParams struct {
Slug string
Favourites []int64
}
func (q *Queries) FuncParamIdent(ctx context.Context, arg FuncParamIdentParams) ([]string, error) {
query := funcParamIdent
var queryParams []interface{}
queryParams = append(queryParams, arg.Slug)
if len(arg.Favourites) > 0 {
for _, v := range arg.Favourites {
queryParams = append(queryParams, v)
}
query = strings.Replace(query, "/*SLICE:favourites*/?", strings.Repeat(",?", len(arg.Favourites))[1:], 1)
} else {
query = strings.Replace(query, "/*SLICE:favourites*/?", "NULL", 1)
}
rows, err := q.query(ctx, nil, query, queryParams...)
if err != nil {
return nil, err
}
defer rows.Close()
var items []string
for rows.Next() {
var name string
if err := rows.Scan(&name); err != nil {
return nil, err
}
items = append(items, name)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}