forked from aakash-rajur/sqlxgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
movie.gen.go
359 lines (332 loc) · 9.83 KB
/
movie.gen.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
package models
// ************************************************************
// This is an example Postgres generated model.
// ************************************************************
// Options:
// postgresInt64JsonString: true
// createdDateFields: created_at
// updatedDateFields: updated_at
import (
"fmt"
"github.com/lib/pq"
"strings"
"time"
)
type Movie struct {
Id *int32 `db:"id" json:"id"`
Budget *int64 `db:"budget" json:"budget,string"`
ClientId *string `db:"client_id" json:"client_id"`
CompletedCoordinates interface{} `db:"completed_coordinates" json:"completed_coordinates"`
CreatedAt *time.Time `db:"created_at" json:"created_at"`
DataSyncedAt *time.Time `db:"data_synced_at" json:"data_synced_at"`
DistanceToPlace *float64 `db:"distance_to_place" json:"distance_to_place"`
Homepage *string `db:"homepage" json:"homepage"`
IsCompleted *bool `db:"is_completed" json:"is_completed"`
Keywords *pq.StringArray `db:"keywords" json:"keywords"`
KeywordsSearch *string `db:"keywords_search" json:"keywords_search"`
LocationAccuracy *int32 `db:"location_accuracy" json:"location_accuracy"`
OriginalLanguage *string `db:"original_language" json:"original_language"`
OriginalTitle *string `db:"original_title" json:"original_title"`
Overview *string `db:"overview" json:"overview"`
Popularity *float64 `db:"popularity" json:"popularity"`
ReleaseDate *time.Time `db:"release_date" json:"release_date"`
Revenue *int64 `db:"revenue" json:"revenue,string"`
Runtime *int32 `db:"runtime" json:"runtime"`
SearchVector *string `db:"search_vector" json:"search_vector"`
Status *string `db:"status" json:"status"`
Summary *string `db:"summary" json:"summary"`
Synopsis *string `db:"synopsis" json:"synopsis"`
Tagline *string `db:"tagline" json:"tagline"`
Title *string `db:"title" json:"title"`
TitleSearch *string `db:"title_search" json:"title_search"`
UpdatedAt *time.Time `db:"updated_at" json:"updated_at"`
VoteAverage *float64 `db:"vote_average" json:"vote_average"`
VoteCount *int32 `db:"vote_count" json:"vote_count"`
}
func (m *Movie) String() string {
content := strings.Join(
[]string{
fmt.Sprintf("Id: %v", *m.Id),
fmt.Sprintf("Budget: %v", *m.Budget),
fmt.Sprintf("ClientId: %v", *m.ClientId),
// fmt.Sprintf("CompletedCoordinates: %v", *m.CompletedCoordinates),
fmt.Sprintf("CreatedAt: %v", *m.CreatedAt),
fmt.Sprintf("DataSyncedAt: %v", *m.DataSyncedAt),
fmt.Sprintf("DistanceToPlace: %v", *m.DistanceToPlace),
fmt.Sprintf("Homepage: %v", *m.Homepage),
fmt.Sprintf("IsCompleted: %v", *m.IsCompleted),
fmt.Sprintf("Keywords: %v", *m.Keywords),
fmt.Sprintf("KeywordsSearch: %v", *m.KeywordsSearch),
fmt.Sprintf("LocationAccuracy: %v", *m.LocationAccuracy),
fmt.Sprintf("OriginalLanguage: %v", *m.OriginalLanguage),
fmt.Sprintf("OriginalTitle: %v", *m.OriginalTitle),
fmt.Sprintf("Overview: %v", *m.Overview),
fmt.Sprintf("Popularity: %v", *m.Popularity),
fmt.Sprintf("ReleaseDate: %v", *m.ReleaseDate),
fmt.Sprintf("Revenue: %v", *m.Revenue),
fmt.Sprintf("Runtime: %v", *m.Runtime),
fmt.Sprintf("SearchVector: %v", *m.SearchVector),
fmt.Sprintf("Status: %v", *m.Status),
fmt.Sprintf("Summary: %v", *m.Summary),
fmt.Sprintf("Synopsis: %v", *m.Synopsis),
fmt.Sprintf("Tagline: %v", *m.Tagline),
fmt.Sprintf("Title: %v", *m.Title),
fmt.Sprintf("TitleSearch: %v", *m.TitleSearch),
fmt.Sprintf("UpdatedAt: %v", *m.UpdatedAt),
fmt.Sprintf("VoteAverage: %v", *m.VoteAverage),
fmt.Sprintf("VoteCount: %v", *m.VoteCount),
},
", ",
)
return fmt.Sprintf("Movie{%s}", content)
}
func (m *Movie) TableName() string {
return "public.movies"
}
func (m *Movie) PrimaryKey() []string {
return []string{
"id",
}
}
func (m *Movie) InsertQuery() string {
return movieInsertSql
}
func (m *Movie) CountQuery() string {
return movieModelCountSql
}
func (m *Movie) FindAllQuery() string {
return movieFindAllSql
}
func (m *Movie) FindFirstQuery() string {
return movieFindFirstSql
}
func (m *Movie) FindByPkQuery() string {
return movieFindByPkSql
}
func (m *Movie) DeleteByPkQuery() string {
return movieDeleteByPkSql
}
func (m *Movie) DeleteAllQuery() string {
return movieDeleteAllSql
}
func (m *Movie) GetPkWhere() string {
return moviePkFieldsWhere
}
func (m *Movie) GetAllFieldsWhere() string {
return movieAllFieldsWhere
}
func (m *Movie) GetReturning() string {
return movieReturningFields
}
// language=postgresql
var movieAllFieldsWhere = `
WHERE TRUE
AND (CAST(:id AS INT4) IS NULL or id = :id)
AND (CAST(:budget AS INT8) IS NULL or budget = :budget)
AND (CAST(:client_id AS VARCHAR) IS NULL or client_id = :client_id)
-- completed_coordinates / POINT is not supported here
AND (CAST(:created_at AS TIMESTAMP) IS NULL or created_at = :created_at)
AND (CAST(:data_synced_at AS TIMESTAMP) IS NULL or data_synced_at = :data_synced_at)
AND (CAST(:distance_to_place AS NUMERIC) IS NULL or distance_to_place = :distance_to_place)
AND (CAST(:homepage AS TEXT) IS NULL or homepage = :homepage)
AND (CAST(:is_completed AS BOOL) IS NULL or is_completed = :is_completed)
AND (CAST(:keywords AS TEXT) IS NULL or keywords = :keywords)
AND (CAST(:keywords_search AS TSVECTOR) IS NULL or keywords_search = :keywords_search)
AND (CAST(:location_accuracy AS INT4) IS NULL or location_accuracy = :location_accuracy)
AND (CAST(:original_language AS TEXT) IS NULL or original_language = :original_language)
AND (CAST(:original_title AS TEXT) IS NULL or original_title = :original_title)
AND (CAST(:overview AS TEXT) IS NULL or overview = :overview)
AND (CAST(:popularity AS FLOAT8) IS NULL or popularity = :popularity)
AND (CAST(:release_date AS DATE) IS NULL or release_date = :release_date)
AND (CAST(:revenue AS INT8) IS NULL or revenue = :revenue)
AND (CAST(:runtime AS INT4) IS NULL or runtime = :runtime)
AND (CAST(:search_vector AS TSVECTOR) IS NULL or search_vector = :search_vector)
AND (CAST(:status AS TEXT) IS NULL or status = :status)
AND (CAST(:summary AS VARCHAR) IS NULL or summary = :summary)
AND (CAST(:synopsis AS VARCHAR) IS NULL or synopsis = :synopsis)
AND (CAST(:tagline AS TEXT) IS NULL or tagline = :tagline)
AND (CAST(:title AS TEXT) IS NULL or title = :title)
AND (CAST(:title_search AS TSVECTOR) IS NULL or title_search = :title_search)
AND (CAST(:updated_at AS TIMESTAMP) IS NULL or updated_at = :updated_at)
AND (CAST(:vote_average AS FLOAT8) IS NULL or vote_average = :vote_average)
AND (CAST(:vote_count AS INT4) IS NULL or vote_count = :vote_count)
`
// language=postgresql
var moviePkFieldsWhere = `
WHERE id = :id
`
// language=postgresql
var movieReturningFields = `
RETURNING id,
budget,
client_id,
completed_coordinates,
created_at,
data_synced_at,
distance_to_place,
homepage,
is_completed,
keywords,
keywords_search,
location_accuracy,
original_language,
original_title,
overview,
popularity,
release_date,
revenue,
runtime,
search_vector,
status,
summary,
synopsis,
tagline,
title,
title_search,
updated_at,
vote_average,
vote_count;
`
// language=postgresql
var movieInsertSql = `
INSERT INTO public.movies(
budget,
client_id,
completed_coordinates,
created_at,
data_synced_at,
distance_to_place,
homepage,
is_completed,
keywords,
location_accuracy,
original_language,
original_title,
overview,
popularity,
release_date,
revenue,
runtime,
search_vector,
status,
summary,
synopsis,
tagline,
title,
updated_at,
vote_average,
vote_count
)
VALUES (
:budget,
:client_id,
:completed_coordinates,
now(),
:data_synced_at,
:distance_to_place,
:homepage,
:is_completed,
:keywords,
:location_accuracy,
:original_language,
:original_title,
:overview,
:popularity,
:release_date,
:revenue,
:runtime,
:search_vector,
:status,
:summary,
:synopsis,
:tagline,
:title,
now(),
:vote_average,
:vote_count
)` + movieReturningFields + ";"
// language=postgresql
var movieModelCountSql = `
SELECT count(*) as count
FROM public.movies
` + movieAllFieldsWhere + ";"
// language=postgresql
var movieFindAllSql = `
SELECT
id,
budget,
client_id,
completed_coordinates,
created_at,
data_synced_at,
distance_to_place,
homepage,
is_completed,
keywords,
keywords_search,
location_accuracy,
original_language,
original_title,
overview,
popularity,
release_date,
revenue,
runtime,
search_vector,
status,
summary,
synopsis,
tagline,
title,
title_search,
updated_at,
vote_average,
vote_count
FROM public.movies
` + movieAllFieldsWhere + ";"
// language=postgresql
var movieFindFirstSql = strings.TrimRight(movieFindAllSql, ";") + `
LIMIT 1;`
// language=postgresql
var movieFindByPkSql = `
SELECT
id,
budget,
client_id,
completed_coordinates,
created_at,
data_synced_at,
distance_to_place,
homepage,
is_completed,
keywords,
keywords_search,
location_accuracy,
original_language,
original_title,
overview,
popularity,
release_date,
revenue,
runtime,
search_vector,
status,
summary,
synopsis,
tagline,
title,
title_search,
updated_at,
vote_average,
vote_count
FROM public.movies
` + moviePkFieldsWhere + `
LIMIT 1;`
// language=postgresql
var movieDeleteByPkSql = `
DELETE FROM public.movies
` + moviePkFieldsWhere + ";"
// language=postgresql
var movieDeleteAllSql = `
DELETE FROM public.movies
` + movieAllFieldsWhere + ";"