-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollections.sql.go
More file actions
160 lines (142 loc) · 3.52 KB
/
Copy pathcollections.sql.go
File metadata and controls
160 lines (142 loc) · 3.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.0
// source: collections.sql
package database
import (
"context"
)
const countCollections = `-- name: CountCollections :one
SELECT COUNT(*) FROM collections
`
func (q *Queries) CountCollections(ctx context.Context) (int64, error) {
row := q.db.QueryRowContext(ctx, countCollections)
var count int64
err := row.Scan(&count)
return count, err
}
const createCollection = `-- name: CreateCollection :one
INSERT INTO collections (name) VALUES (?) RETURNING id, name, created_at, updated_at
`
func (q *Queries) CreateCollection(ctx context.Context, name string) (Collection, error) {
row := q.db.QueryRowContext(ctx, createCollection, name)
var i Collection
err := row.Scan(
&i.ID,
&i.Name,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const deleteCollection = `-- name: DeleteCollection :exec
DELETE FROM collections
WHERE id = ?
`
func (q *Queries) DeleteCollection(ctx context.Context, id int64) error {
_, err := q.db.ExecContext(ctx, deleteCollection, id)
return err
}
const getCollection = `-- name: GetCollection :one
SELECT id, name, created_at, updated_at FROM collections
WHERE id = ?
`
func (q *Queries) GetCollection(ctx context.Context, id int64) (Collection, error) {
row := q.db.QueryRowContext(ctx, getCollection, id)
var i Collection
err := row.Scan(
&i.ID,
&i.Name,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getCollections = `-- name: GetCollections :many
SELECT id, name, created_at, updated_at FROM collections
ORDER BY created_at DESC
`
func (q *Queries) GetCollections(ctx context.Context) ([]Collection, error) {
rows, err := q.db.QueryContext(ctx, getCollections)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Collection
for rows.Next() {
var i Collection
if err := rows.Scan(
&i.ID,
&i.Name,
&i.CreatedAt,
&i.UpdatedAt,
); 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 getCollectionsPaginated = `-- name: GetCollectionsPaginated :many
SELECT id, name, created_at, updated_at FROM collections
ORDER BY created_at DESC
LIMIT ? OFFSET ?
`
type GetCollectionsPaginatedParams struct {
Limit int64 `db:"limit" json:"limit"`
Offset int64 `db:"offset" json:"offset"`
}
func (q *Queries) GetCollectionsPaginated(ctx context.Context, arg GetCollectionsPaginatedParams) ([]Collection, error) {
rows, err := q.db.QueryContext(ctx, getCollectionsPaginated, arg.Limit, arg.Offset)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Collection
for rows.Next() {
var i Collection
if err := rows.Scan(
&i.ID,
&i.Name,
&i.CreatedAt,
&i.UpdatedAt,
); 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 updateCollectionName = `-- name: UpdateCollectionName :one
UPDATE collections
SET name = ?
WHERE id = ?
RETURNING id, name, created_at, updated_at
`
type UpdateCollectionNameParams struct {
Name string `db:"name" json:"name"`
ID int64 `db:"id" json:"id"`
}
func (q *Queries) UpdateCollectionName(ctx context.Context, arg UpdateCollectionNameParams) (Collection, error) {
row := q.db.QueryRowContext(ctx, updateCollectionName, arg.Name, arg.ID)
var i Collection
err := row.Scan(
&i.ID,
&i.Name,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}