/
queries.sql.go
189 lines (168 loc) · 4.17 KB
/
queries.sql.go
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.24.0
// source: queries.sql
package db
import (
"context"
)
const countQuestionByTitleSlug = `-- name: CountQuestionByTitleSlug :one
select count(*) from question where title_slug = ?
`
func (q *Queries) CountQuestionByTitleSlug(ctx context.Context, titleSlug string) (int64, error) {
row := q.db.QueryRowContext(ctx, countQuestionByTitleSlug, titleSlug)
var count int64
err := row.Scan(&count)
return count, err
}
const getEditors = `-- name: GetEditors :many
select id, question_id, lang, lang_slug, code from editor where question_id = ? and lang_slug = ?
`
type GetEditorsParams struct {
QuestionID string
LangSlug string
}
func (q *Queries) GetEditors(ctx context.Context, arg GetEditorsParams) ([]Editor, error) {
rows, err := q.db.QueryContext(ctx, getEditors, arg.QuestionID, arg.LangSlug)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Editor
for rows.Next() {
var i Editor
if err := rows.Scan(
&i.ID,
&i.QuestionID,
&i.Lang,
&i.LangSlug,
&i.Code,
); 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 getHints = `-- name: GetHints :many
select id, question_id, hint from hint where question_id = ?
`
func (q *Queries) GetHints(ctx context.Context, questionID string) ([]Hint, error) {
rows, err := q.db.QueryContext(ctx, getHints, questionID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Hint
for rows.Next() {
var i Hint
if err := rows.Scan(&i.ID, &i.QuestionID, &i.Hint); 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 getQuestions = `-- name: GetQuestions :many
select id, question_id, link, title, title_slug, is_paid_only, difficulty, content from question where cast(question_id as integer) >= cast(?1 as integer) and cast(question_id as integer) <= cast(?2 as integer)
`
type GetQuestionsParams struct {
From int64
To int64
}
func (q *Queries) GetQuestions(ctx context.Context, arg GetQuestionsParams) ([]Question, error) {
rows, err := q.db.QueryContext(ctx, getQuestions, arg.From, arg.To)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Question
for rows.Next() {
var i Question
if err := rows.Scan(
&i.ID,
&i.QuestionID,
&i.Link,
&i.Title,
&i.TitleSlug,
&i.IsPaidOnly,
&i.Difficulty,
&i.Content,
); 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 insertEditor = `-- name: InsertEditor :exec
insert into editor(question_id, lang, lang_slug, code) values (?, ?, ?, ?)
`
type InsertEditorParams struct {
QuestionID string
Lang string
LangSlug string
Code string
}
func (q *Queries) InsertEditor(ctx context.Context, arg InsertEditorParams) error {
_, err := q.db.ExecContext(ctx, insertEditor,
arg.QuestionID,
arg.Lang,
arg.LangSlug,
arg.Code,
)
return err
}
const insertHint = `-- name: InsertHint :exec
insert into hint(question_id, hint) values (?, ?)
`
type InsertHintParams struct {
QuestionID string
Hint string
}
func (q *Queries) InsertHint(ctx context.Context, arg InsertHintParams) error {
_, err := q.db.ExecContext(ctx, insertHint, arg.QuestionID, arg.Hint)
return err
}
const insertQuestion = `-- name: InsertQuestion :exec
insert into question(question_id, link, title, title_slug, is_paid_only, difficulty, content) values (?, ?, ?, ?, ?, ?, ?)
`
type InsertQuestionParams struct {
QuestionID string
Link string
Title string
TitleSlug string
IsPaidOnly bool
Difficulty string
Content string
}
func (q *Queries) InsertQuestion(ctx context.Context, arg InsertQuestionParams) error {
_, err := q.db.ExecContext(ctx, insertQuestion,
arg.QuestionID,
arg.Link,
arg.Title,
arg.TitleSlug,
arg.IsPaidOnly,
arg.Difficulty,
arg.Content,
)
return err
}