1
|
|
|
package cli |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"testing" |
5
|
|
|
|
6
|
|
|
"github.com/stretchr/testify/assert" |
7
|
|
|
"github.com/stretchr/testify/mock" |
8
|
|
|
|
9
|
|
|
"github.com/fraenky8/tables-to-go/pkg/database" |
10
|
|
|
"github.com/fraenky8/tables-to-go/pkg/settings" |
11
|
|
|
) |
12
|
|
|
|
13
|
|
|
type mockDb struct { |
14
|
|
|
mock.Mock |
15
|
|
|
database.Database |
16
|
|
|
|
17
|
|
|
tables []*database.Table |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
func newMockDb(db database.Database) *mockDb { |
21
|
|
|
return &mockDb{Database: db} |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
func (db *mockDb) Connect() (err error) { |
25
|
|
|
db.Called() |
26
|
|
|
return nil |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
func (db *mockDb) Close() (err error) { |
30
|
|
|
db.Called() |
31
|
|
|
return nil |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
func (db *mockDb) GetTables() (tables []*database.Table, err error) { |
35
|
|
|
db.Called() |
36
|
|
|
return db.tables, nil |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
func (db *mockDb) PrepareGetColumnsOfTableStmt() (err error) { |
40
|
|
|
db.Called() |
41
|
|
|
return nil |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
func (db *mockDb) GetColumnsOfTable(table *database.Table) (err error) { |
45
|
|
|
db.Called(table) |
46
|
|
|
return nil |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
type mockWriter struct { |
50
|
|
|
mock.Mock |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
func newMockWriter() *mockWriter { |
54
|
|
|
return &mockWriter{} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
func (w *mockWriter) Write(tableName string, content string) error { |
58
|
|
|
w.Called(tableName, content) |
59
|
|
|
return nil |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
func TestCamelCaseString(t *testing.T) { |
63
|
|
|
tests := []struct { |
64
|
|
|
desc string |
65
|
|
|
input string |
66
|
|
|
expected string |
67
|
|
|
}{ |
68
|
|
|
{ |
69
|
|
|
desc: "empty string returns empty string", |
70
|
|
|
input: "", |
71
|
|
|
expected: "", |
72
|
|
|
}, |
73
|
|
|
{ |
74
|
|
|
desc: "single string returns titleized single string", |
75
|
|
|
input: "string", |
76
|
|
|
expected: "String", |
77
|
|
|
}, |
78
|
|
|
{ |
79
|
|
|
desc: "multi separated string returns CamelCase string", |
80
|
|
|
input: "string_with_separate_sections", |
81
|
|
|
expected: "StringWithSeparateSections", |
82
|
|
|
}, |
83
|
|
|
} |
84
|
|
|
for _, tt := range tests { |
85
|
|
|
t.Run(tt.desc, func(t *testing.T) { |
86
|
|
|
actual := camelCaseString(tt.input) |
87
|
|
|
assert.Equal(t, tt.expected, actual, "test case input: "+tt.input) |
88
|
|
|
}) |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
func TestToInitialisms(t *testing.T) { |
93
|
|
|
tests := []struct { |
94
|
|
|
desc string |
95
|
|
|
input string |
96
|
|
|
expected string |
97
|
|
|
}{ |
98
|
|
|
{ |
99
|
|
|
desc: "id should be upper case", |
100
|
|
|
input: "Id", |
101
|
|
|
expected: "ID", |
102
|
|
|
}, |
103
|
|
|
{ |
104
|
|
|
desc: "id at the end of string should be upper case", |
105
|
|
|
input: "userId", |
106
|
|
|
expected: "userID", |
107
|
|
|
}, |
108
|
|
|
{ |
109
|
|
|
desc: "id at the beginning of string should be upper case", |
110
|
|
|
input: "Iduser", |
111
|
|
|
expected: "IDuser", |
112
|
|
|
}, |
113
|
|
|
{ |
114
|
|
|
desc: "id in the middle of string should be upper case", |
115
|
|
|
input: "userIdprim", |
116
|
|
|
expected: "userIDprim", |
117
|
|
|
}, |
118
|
|
|
{ |
119
|
|
|
desc: "multiple occurrences should be upper case", |
120
|
|
|
input: "userIdasJsonWithUrl", |
121
|
|
|
expected: "userIDasJSONWithURL", |
122
|
|
|
}, |
123
|
|
|
{ |
124
|
|
|
desc: "multiple id in the string should be upper case", |
125
|
|
|
input: "IduserId", |
126
|
|
|
expected: "IDuserID", |
127
|
|
|
}, |
128
|
|
|
{ |
129
|
|
|
desc: "non replacement in the string should be return original string", |
130
|
|
|
input: "name", |
131
|
|
|
expected: "name", |
132
|
|
|
}, |
133
|
|
|
{ |
134
|
|
|
desc: "replacements only in the string should be return original string", |
135
|
|
|
input: "IdjsonuRlHtTp", |
136
|
|
|
expected: "IDJSONURLHTTP", |
137
|
|
|
}, |
138
|
|
|
} |
139
|
|
|
for _, tt := range tests { |
140
|
|
|
t.Run(tt.desc, func(t *testing.T) { |
141
|
|
|
actual := toInitialisms(tt.input) |
142
|
|
|
assert.Equal(t, tt.expected, actual, "test case input: "+tt.input) |
143
|
|
|
}) |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
func TestRun_StringTextColumns(t *testing.T) { |
148
|
|
|
for dbType := range settings.SupportedDbTypes { |
149
|
|
|
t.Run(dbType.String(), func(t *testing.T) { |
150
|
|
|
|
151
|
|
|
s := settings.New() |
152
|
|
|
s.DbType = dbType |
153
|
|
|
db := database.New(s) |
154
|
|
|
|
155
|
|
|
columnTypes := db.GetStringDatatypes() |
156
|
|
|
|
157
|
|
|
for _, columnType := range columnTypes { |
158
|
|
|
t.Run(columnType, func(t *testing.T) { |
159
|
|
|
|
160
|
|
|
t.Run("single table with NOT NULL column", func(t *testing.T) { |
161
|
|
|
s := settings.New() |
162
|
|
|
s.DbType = dbType |
163
|
|
|
|
164
|
|
|
mdb := newMockDb(db) |
165
|
|
|
|
166
|
|
|
table := &database.Table{ |
167
|
|
|
Name: "test_table", |
168
|
|
|
Columns: []database.Column{ |
169
|
|
|
{ |
170
|
|
|
OrdinalPosition: 1, |
171
|
|
|
Name: "column_name", |
172
|
|
|
DataType: columnType, |
173
|
|
|
}, |
174
|
|
|
}, |
175
|
|
|
} |
176
|
|
|
mdb.tables = append(mdb.tables, table) |
177
|
|
|
|
178
|
|
|
mdb. |
179
|
|
|
On("GetTables"). |
180
|
|
|
Return(mdb.tables, nil) |
181
|
|
|
mdb. |
182
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
183
|
|
|
Return(nil) |
184
|
|
|
mdb. |
185
|
|
|
On("GetColumnsOfTable", table) |
186
|
|
|
|
187
|
|
|
w := newMockWriter() |
188
|
|
|
w. |
189
|
|
|
On( |
190
|
|
|
"Write", |
191
|
|
|
"TestTable", |
192
|
|
|
"package dto\n\ntype TestTable struct {\nColumnName string `db:\"column_name\"`\n}", |
193
|
|
|
) |
194
|
|
|
|
195
|
|
|
err := Run(s, mdb, w) |
196
|
|
|
assert.NoError(t, err) |
197
|
|
|
}) |
198
|
|
|
|
199
|
|
|
t.Run("single table with NULL column", func(t *testing.T) { |
200
|
|
|
s := settings.New() |
201
|
|
|
s.DbType = dbType |
202
|
|
|
|
203
|
|
|
mdb := newMockDb(db) |
204
|
|
|
|
205
|
|
|
table := &database.Table{ |
206
|
|
|
Name: "test_table", |
207
|
|
|
Columns: []database.Column{ |
208
|
|
|
{ |
209
|
|
|
OrdinalPosition: 1, |
210
|
|
|
Name: "column_name", |
211
|
|
|
DataType: columnType, |
212
|
|
|
IsNullable: "YES", |
213
|
|
|
}, |
214
|
|
|
}, |
215
|
|
|
} |
216
|
|
|
mdb.tables = append(mdb.tables, table) |
217
|
|
|
|
218
|
|
|
mdb. |
219
|
|
|
On("GetTables"). |
220
|
|
|
Return(mdb.tables, nil) |
221
|
|
|
mdb. |
222
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
223
|
|
|
Return(nil) |
224
|
|
|
mdb. |
225
|
|
|
On("GetColumnsOfTable", table) |
226
|
|
|
|
227
|
|
|
w := newMockWriter() |
228
|
|
|
w. |
229
|
|
|
On( |
230
|
|
|
"Write", |
231
|
|
|
"TestTable", |
232
|
|
|
"package dto\n\nimport (\n\t\"database/sql\"\n)\n\ntype TestTable struct {\nColumnName sql.NullString `db:\"column_name\"`\n}", |
233
|
|
|
) |
234
|
|
|
|
235
|
|
|
err := Run(s, mdb, w) |
236
|
|
|
assert.NoError(t, err) |
237
|
|
|
}) |
238
|
|
|
|
239
|
|
|
t.Run("single table with NULL column and native data type", func(t *testing.T) { |
240
|
|
|
s := settings.New() |
241
|
|
|
s.DbType = dbType |
242
|
|
|
s.Null = settings.NullTypeNative |
243
|
|
|
|
244
|
|
|
mdb := newMockDb(db) |
245
|
|
|
|
246
|
|
|
table := &database.Table{ |
247
|
|
|
Name: "test_table", |
248
|
|
|
Columns: []database.Column{ |
249
|
|
|
{ |
250
|
|
|
OrdinalPosition: 1, |
251
|
|
|
Name: "column_name", |
252
|
|
|
DataType: columnType, |
253
|
|
|
IsNullable: "YES", |
254
|
|
|
}, |
255
|
|
|
}, |
256
|
|
|
} |
257
|
|
|
mdb.tables = append(mdb.tables, table) |
258
|
|
|
|
259
|
|
|
mdb. |
260
|
|
|
On("GetTables"). |
261
|
|
|
Return(mdb.tables, nil) |
262
|
|
|
mdb. |
263
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
264
|
|
|
Return(nil) |
265
|
|
|
mdb. |
266
|
|
|
On("GetColumnsOfTable", table) |
267
|
|
|
|
268
|
|
|
w := newMockWriter() |
269
|
|
|
w. |
270
|
|
|
On( |
271
|
|
|
"Write", |
272
|
|
|
"TestTable", |
273
|
|
|
"package dto\n\nimport (\n)\n\ntype TestTable struct {\nColumnName *string `db:\"column_name\"`\n}", |
274
|
|
|
) |
275
|
|
|
|
276
|
|
|
err := Run(s, mdb, w) |
277
|
|
|
assert.NoError(t, err) |
278
|
|
|
}) |
279
|
|
|
|
280
|
|
|
t.Run("single table with two mixed columns", func(t *testing.T) { |
281
|
|
|
s := settings.New() |
282
|
|
|
s.DbType = dbType |
283
|
|
|
|
284
|
|
|
mdb := newMockDb(db) |
285
|
|
|
|
286
|
|
|
table := &database.Table{ |
287
|
|
|
Name: "test_table", |
288
|
|
|
Columns: []database.Column{ |
289
|
|
|
{ |
290
|
|
|
OrdinalPosition: 1, |
291
|
|
|
Name: "column_name_1", |
292
|
|
|
DataType: columnType, |
293
|
|
|
IsNullable: "YES", |
294
|
|
|
}, |
295
|
|
|
{ |
296
|
|
|
OrdinalPosition: 2, |
297
|
|
|
Name: "column_name_2", |
298
|
|
|
DataType: columnType, |
299
|
|
|
}, |
300
|
|
|
}, |
301
|
|
|
} |
302
|
|
|
mdb.tables = append(mdb.tables, table) |
303
|
|
|
|
304
|
|
|
mdb. |
305
|
|
|
On("GetTables"). |
306
|
|
|
Return(mdb.tables, nil) |
307
|
|
|
mdb. |
308
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
309
|
|
|
Return(nil) |
310
|
|
|
mdb. |
311
|
|
|
On("GetColumnsOfTable", table) |
312
|
|
|
|
313
|
|
|
w := newMockWriter() |
314
|
|
|
w. |
315
|
|
|
On( |
316
|
|
|
"Write", |
317
|
|
|
"TestTable", |
318
|
|
|
"package dto\n\nimport (\n\t\"database/sql\"\n)\n\ntype TestTable struct {\nColumnName1 sql.NullString `db:\"column_name_1\"`\nColumnName2 string `db:\"column_name_2\"`\n}", |
319
|
|
|
) |
320
|
|
|
|
321
|
|
|
err := Run(s, mdb, w) |
322
|
|
|
assert.NoError(t, err) |
323
|
|
|
}) |
324
|
|
|
|
325
|
|
|
t.Run("single table with two mixed columns and native data type", func(t *testing.T) { |
326
|
|
|
s := settings.New() |
327
|
|
|
s.DbType = dbType |
328
|
|
|
s.Null = settings.NullTypeNative |
329
|
|
|
|
330
|
|
|
mdb := newMockDb(db) |
331
|
|
|
|
332
|
|
|
table := &database.Table{ |
333
|
|
|
Name: "test_table", |
334
|
|
|
Columns: []database.Column{ |
335
|
|
|
{ |
336
|
|
|
OrdinalPosition: 1, |
337
|
|
|
Name: "column_name_1", |
338
|
|
|
DataType: columnType, |
339
|
|
|
IsNullable: "YES", |
340
|
|
|
}, |
341
|
|
|
{ |
342
|
|
|
OrdinalPosition: 2, |
343
|
|
|
Name: "column_name_2", |
344
|
|
|
DataType: columnType, |
345
|
|
|
}, |
346
|
|
|
}, |
347
|
|
|
} |
348
|
|
|
mdb.tables = append(mdb.tables, table) |
349
|
|
|
|
350
|
|
|
mdb. |
351
|
|
|
On("GetTables"). |
352
|
|
|
Return(mdb.tables, nil) |
353
|
|
|
mdb. |
354
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
355
|
|
|
Return(nil) |
356
|
|
|
mdb. |
357
|
|
|
On("GetColumnsOfTable", table) |
358
|
|
|
|
359
|
|
|
w := newMockWriter() |
360
|
|
|
w. |
361
|
|
|
On( |
362
|
|
|
"Write", |
363
|
|
|
"TestTable", |
364
|
|
|
"package dto\n\nimport (\n)\n\ntype TestTable struct {\nColumnName1 *string `db:\"column_name_1\"`\nColumnName2 string `db:\"column_name_2\"`\n}", |
365
|
|
|
) |
366
|
|
|
|
367
|
|
|
err := Run(s, mdb, w) |
368
|
|
|
assert.NoError(t, err) |
369
|
|
|
}) |
370
|
|
|
|
371
|
|
|
t.Run("multi table with multi columns", func(t *testing.T) { |
372
|
|
|
s := settings.New() |
373
|
|
|
s.DbType = dbType |
374
|
|
|
|
375
|
|
|
mdb := newMockDb(db) |
376
|
|
|
|
377
|
|
|
table1 := &database.Table{ |
378
|
|
|
Name: "test_table_1", |
379
|
|
|
Columns: []database.Column{ |
380
|
|
|
{ |
381
|
|
|
OrdinalPosition: 1, |
382
|
|
|
Name: "column_name_1", |
383
|
|
|
DataType: columnType, |
384
|
|
|
IsNullable: "YES", |
385
|
|
|
}, |
386
|
|
|
{ |
387
|
|
|
OrdinalPosition: 2, |
388
|
|
|
Name: "column_name_2", |
389
|
|
|
DataType: columnType, |
390
|
|
|
}, |
391
|
|
|
}, |
392
|
|
|
} |
393
|
|
|
table2 := &database.Table{ |
394
|
|
|
Name: "test_table_2", |
395
|
|
|
Columns: []database.Column{ |
396
|
|
|
{ |
397
|
|
|
OrdinalPosition: 1, |
398
|
|
|
Name: "column_name_1", |
399
|
|
|
DataType: columnType, |
400
|
|
|
}, |
401
|
|
|
{ |
402
|
|
|
OrdinalPosition: 2, |
403
|
|
|
Name: "column_name_2", |
404
|
|
|
DataType: columnType, |
405
|
|
|
IsNullable: "YES", |
406
|
|
|
}, |
407
|
|
|
}, |
408
|
|
|
} |
409
|
|
|
mdb.tables = append(mdb.tables, table1, table2) |
410
|
|
|
|
411
|
|
|
mdb. |
412
|
|
|
On("GetTables"). |
413
|
|
|
Return(mdb.tables, nil) |
414
|
|
|
mdb. |
415
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
416
|
|
|
Return(nil) |
417
|
|
|
mdb. |
418
|
|
|
On("GetColumnsOfTable", table1). |
419
|
|
|
On("GetColumnsOfTable", table2) |
420
|
|
|
|
421
|
|
|
w := newMockWriter() |
422
|
|
|
w. |
423
|
|
|
On( |
424
|
|
|
"Write", |
425
|
|
|
"TestTable1", |
426
|
|
|
"package dto\n\nimport (\n\t\"database/sql\"\n)\n\ntype TestTable1 struct {\nColumnName1 sql.NullString `db:\"column_name_1\"`\nColumnName2 string `db:\"column_name_2\"`\n}", |
427
|
|
|
). |
428
|
|
|
On( |
429
|
|
|
"Write", |
430
|
|
|
"TestTable2", |
431
|
|
|
"package dto\n\nimport (\n\t\"database/sql\"\n)\n\ntype TestTable2 struct {\nColumnName1 string `db:\"column_name_1\"`\nColumnName2 sql.NullString `db:\"column_name_2\"`\n}", |
432
|
|
|
) |
433
|
|
|
|
434
|
|
|
err := Run(s, mdb, w) |
435
|
|
|
assert.NoError(t, err) |
436
|
|
|
}) |
437
|
|
|
}) |
438
|
|
|
} |
439
|
|
|
}) |
440
|
|
|
} |
441
|
|
|
} |
442
|
|
|
|
443
|
|
|
func TestRun_IntegerColumns(t *testing.T) { |
444
|
|
|
for dbType := range settings.SupportedDbTypes { |
445
|
|
|
t.Run(dbType.String(), func(t *testing.T) { |
446
|
|
|
|
447
|
|
|
s := settings.New() |
448
|
|
|
s.DbType = dbType |
449
|
|
|
db := database.New(s) |
450
|
|
|
|
451
|
|
|
columnTypes := db.GetIntegerDatatypes() |
452
|
|
|
|
453
|
|
|
for _, columnType := range columnTypes { |
454
|
|
|
t.Run(columnType, func(t *testing.T) { |
455
|
|
|
|
456
|
|
|
t.Run("single table with NOT NULL column", func(t *testing.T) { |
457
|
|
|
s := settings.New() |
458
|
|
|
s.DbType = dbType |
459
|
|
|
|
460
|
|
|
mdb := newMockDb(db) |
461
|
|
|
|
462
|
|
|
table := &database.Table{ |
463
|
|
|
Name: "test_table", |
464
|
|
|
Columns: []database.Column{ |
465
|
|
|
{ |
466
|
|
|
OrdinalPosition: 1, |
467
|
|
|
Name: "column_name", |
468
|
|
|
DataType: columnType, |
469
|
|
|
}, |
470
|
|
|
}, |
471
|
|
|
} |
472
|
|
|
mdb.tables = append(mdb.tables, table) |
473
|
|
|
|
474
|
|
|
mdb. |
475
|
|
|
On("GetTables"). |
476
|
|
|
Return(mdb.tables, nil) |
477
|
|
|
mdb. |
478
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
479
|
|
|
Return(nil) |
480
|
|
|
mdb. |
481
|
|
|
On("GetColumnsOfTable", table) |
482
|
|
|
|
483
|
|
|
w := newMockWriter() |
484
|
|
|
w. |
485
|
|
|
On( |
486
|
|
|
"Write", |
487
|
|
|
"TestTable", |
488
|
|
|
"package dto\n\ntype TestTable struct {\nColumnName int `db:\"column_name\"`\n}", |
489
|
|
|
) |
490
|
|
|
|
491
|
|
|
err := Run(s, mdb, w) |
492
|
|
|
assert.NoError(t, err) |
493
|
|
|
}) |
494
|
|
|
|
495
|
|
|
t.Run("single table with NULL column", func(t *testing.T) { |
496
|
|
|
s := settings.New() |
497
|
|
|
s.DbType = dbType |
498
|
|
|
|
499
|
|
|
mdb := newMockDb(db) |
500
|
|
|
|
501
|
|
|
table := &database.Table{ |
502
|
|
|
Name: "test_table", |
503
|
|
|
Columns: []database.Column{ |
504
|
|
|
{ |
505
|
|
|
OrdinalPosition: 1, |
506
|
|
|
Name: "column_name", |
507
|
|
|
DataType: columnType, |
508
|
|
|
IsNullable: "YES", |
509
|
|
|
}, |
510
|
|
|
}, |
511
|
|
|
} |
512
|
|
|
mdb.tables = append(mdb.tables, table) |
513
|
|
|
|
514
|
|
|
mdb. |
515
|
|
|
On("GetTables"). |
516
|
|
|
Return(mdb.tables, nil) |
517
|
|
|
mdb. |
518
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
519
|
|
|
Return(nil) |
520
|
|
|
mdb. |
521
|
|
|
On("GetColumnsOfTable", table) |
522
|
|
|
|
523
|
|
|
w := newMockWriter() |
524
|
|
|
w. |
525
|
|
|
On( |
526
|
|
|
"Write", |
527
|
|
|
"TestTable", |
528
|
|
|
"package dto\n\nimport (\n\t\"database/sql\"\n)\n\ntype TestTable struct {\nColumnName sql.NullInt64 `db:\"column_name\"`\n}", |
529
|
|
|
) |
530
|
|
|
|
531
|
|
|
err := Run(s, mdb, w) |
532
|
|
|
assert.NoError(t, err) |
533
|
|
|
}) |
534
|
|
|
|
535
|
|
|
t.Run("single table with NULL column and native data type", func(t *testing.T) { |
536
|
|
|
s := settings.New() |
537
|
|
|
s.DbType = dbType |
538
|
|
|
s.Null = settings.NullTypeNative |
539
|
|
|
|
540
|
|
|
mdb := newMockDb(db) |
541
|
|
|
|
542
|
|
|
table := &database.Table{ |
543
|
|
|
Name: "test_table", |
544
|
|
|
Columns: []database.Column{ |
545
|
|
|
{ |
546
|
|
|
OrdinalPosition: 1, |
547
|
|
|
Name: "column_name", |
548
|
|
|
DataType: columnType, |
549
|
|
|
IsNullable: "YES", |
550
|
|
|
}, |
551
|
|
|
}, |
552
|
|
|
} |
553
|
|
|
mdb.tables = append(mdb.tables, table) |
554
|
|
|
|
555
|
|
|
mdb. |
556
|
|
|
On("GetTables"). |
557
|
|
|
Return(mdb.tables, nil) |
558
|
|
|
mdb. |
559
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
560
|
|
|
Return(nil) |
561
|
|
|
mdb. |
562
|
|
|
On("GetColumnsOfTable", table) |
563
|
|
|
|
564
|
|
|
w := newMockWriter() |
565
|
|
|
w. |
566
|
|
|
On( |
567
|
|
|
"Write", |
568
|
|
|
"TestTable", |
569
|
|
|
"package dto\n\nimport (\n)\n\ntype TestTable struct {\nColumnName *int `db:\"column_name\"`\n}", |
570
|
|
|
) |
571
|
|
|
|
572
|
|
|
err := Run(s, mdb, w) |
573
|
|
|
assert.NoError(t, err) |
574
|
|
|
}) |
575
|
|
|
|
576
|
|
|
t.Run("single table with two mixed columns", func(t *testing.T) { |
577
|
|
|
s := settings.New() |
578
|
|
|
s.DbType = dbType |
579
|
|
|
|
580
|
|
|
mdb := newMockDb(db) |
581
|
|
|
|
582
|
|
|
table := &database.Table{ |
583
|
|
|
Name: "test_table", |
584
|
|
|
Columns: []database.Column{ |
585
|
|
|
{ |
586
|
|
|
OrdinalPosition: 1, |
587
|
|
|
Name: "column_name_1", |
588
|
|
|
DataType: columnType, |
589
|
|
|
IsNullable: "YES", |
590
|
|
|
}, |
591
|
|
|
{ |
592
|
|
|
OrdinalPosition: 2, |
593
|
|
|
Name: "column_name_2", |
594
|
|
|
DataType: columnType, |
595
|
|
|
}, |
596
|
|
|
}, |
597
|
|
|
} |
598
|
|
|
mdb.tables = append(mdb.tables, table) |
599
|
|
|
|
600
|
|
|
mdb. |
601
|
|
|
On("GetTables"). |
602
|
|
|
Return(mdb.tables, nil) |
603
|
|
|
mdb. |
604
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
605
|
|
|
Return(nil) |
606
|
|
|
mdb. |
607
|
|
|
On("GetColumnsOfTable", table) |
608
|
|
|
|
609
|
|
|
w := newMockWriter() |
610
|
|
|
w. |
611
|
|
|
On( |
612
|
|
|
"Write", |
613
|
|
|
"TestTable", |
614
|
|
|
"package dto\n\nimport (\n\t\"database/sql\"\n)\n\ntype TestTable struct {\nColumnName1 sql.NullInt64 `db:\"column_name_1\"`\nColumnName2 int `db:\"column_name_2\"`\n}", |
615
|
|
|
) |
616
|
|
|
|
617
|
|
|
err := Run(s, mdb, w) |
618
|
|
|
assert.NoError(t, err) |
619
|
|
|
}) |
620
|
|
|
|
621
|
|
|
t.Run("single table with two mixed columns and native data type", func(t *testing.T) { |
622
|
|
|
s := settings.New() |
623
|
|
|
s.DbType = dbType |
624
|
|
|
s.Null = settings.NullTypeNative |
625
|
|
|
|
626
|
|
|
mdb := newMockDb(db) |
627
|
|
|
|
628
|
|
|
table := &database.Table{ |
629
|
|
|
Name: "test_table", |
630
|
|
|
Columns: []database.Column{ |
631
|
|
|
{ |
632
|
|
|
OrdinalPosition: 1, |
633
|
|
|
Name: "column_name_1", |
634
|
|
|
DataType: columnType, |
635
|
|
|
IsNullable: "YES", |
636
|
|
|
}, |
637
|
|
|
{ |
638
|
|
|
OrdinalPosition: 2, |
639
|
|
|
Name: "column_name_2", |
640
|
|
|
DataType: columnType, |
641
|
|
|
}, |
642
|
|
|
}, |
643
|
|
|
} |
644
|
|
|
mdb.tables = append(mdb.tables, table) |
645
|
|
|
|
646
|
|
|
mdb. |
647
|
|
|
On("GetTables"). |
648
|
|
|
Return(mdb.tables, nil) |
649
|
|
|
mdb. |
650
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
651
|
|
|
Return(nil) |
652
|
|
|
mdb. |
653
|
|
|
On("GetColumnsOfTable", table) |
654
|
|
|
|
655
|
|
|
w := newMockWriter() |
656
|
|
|
w. |
657
|
|
|
On( |
658
|
|
|
"Write", |
659
|
|
|
"TestTable", |
660
|
|
|
"package dto\n\nimport (\n)\n\ntype TestTable struct {\nColumnName1 *int `db:\"column_name_1\"`\nColumnName2 int `db:\"column_name_2\"`\n}", |
661
|
|
|
) |
662
|
|
|
|
663
|
|
|
err := Run(s, mdb, w) |
664
|
|
|
assert.NoError(t, err) |
665
|
|
|
}) |
666
|
|
|
|
667
|
|
|
t.Run("multi table with multi columns", func(t *testing.T) { |
668
|
|
|
s := settings.New() |
669
|
|
|
s.DbType = dbType |
670
|
|
|
|
671
|
|
|
mdb := newMockDb(db) |
672
|
|
|
|
673
|
|
|
table1 := &database.Table{ |
674
|
|
|
Name: "test_table_1", |
675
|
|
|
Columns: []database.Column{ |
676
|
|
|
{ |
677
|
|
|
OrdinalPosition: 1, |
678
|
|
|
Name: "column_name_1", |
679
|
|
|
DataType: columnType, |
680
|
|
|
IsNullable: "YES", |
681
|
|
|
}, |
682
|
|
|
{ |
683
|
|
|
OrdinalPosition: 2, |
684
|
|
|
Name: "column_name_2", |
685
|
|
|
DataType: columnType, |
686
|
|
|
}, |
687
|
|
|
}, |
688
|
|
|
} |
689
|
|
|
table2 := &database.Table{ |
690
|
|
|
Name: "test_table_2", |
691
|
|
|
Columns: []database.Column{ |
692
|
|
|
{ |
693
|
|
|
OrdinalPosition: 1, |
694
|
|
|
Name: "column_name_1", |
695
|
|
|
DataType: columnType, |
696
|
|
|
}, |
697
|
|
|
{ |
698
|
|
|
OrdinalPosition: 2, |
699
|
|
|
Name: "column_name_2", |
700
|
|
|
DataType: columnType, |
701
|
|
|
IsNullable: "YES", |
702
|
|
|
}, |
703
|
|
|
}, |
704
|
|
|
} |
705
|
|
|
mdb.tables = append(mdb.tables, table1, table2) |
706
|
|
|
|
707
|
|
|
mdb. |
708
|
|
|
On("GetTables"). |
709
|
|
|
Return(mdb.tables, nil) |
710
|
|
|
mdb. |
711
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
712
|
|
|
Return(nil) |
713
|
|
|
mdb. |
714
|
|
|
On("GetColumnsOfTable", table1). |
715
|
|
|
On("GetColumnsOfTable", table2) |
716
|
|
|
|
717
|
|
|
w := newMockWriter() |
718
|
|
|
w. |
719
|
|
|
On( |
720
|
|
|
"Write", |
721
|
|
|
"TestTable1", |
722
|
|
|
"package dto\n\nimport (\n\t\"database/sql\"\n)\n\ntype TestTable1 struct {\nColumnName1 sql.NullInt64 `db:\"column_name_1\"`\nColumnName2 int `db:\"column_name_2\"`\n}", |
723
|
|
|
). |
724
|
|
|
On( |
725
|
|
|
"Write", |
726
|
|
|
"TestTable2", |
727
|
|
|
"package dto\n\nimport (\n\t\"database/sql\"\n)\n\ntype TestTable2 struct {\nColumnName1 int `db:\"column_name_1\"`\nColumnName2 sql.NullInt64 `db:\"column_name_2\"`\n}", |
728
|
|
|
) |
729
|
|
|
|
730
|
|
|
err := Run(s, mdb, w) |
731
|
|
|
assert.NoError(t, err) |
732
|
|
|
}) |
733
|
|
|
}) |
734
|
|
|
} |
735
|
|
|
}) |
736
|
|
|
} |
737
|
|
|
} |
738
|
|
|
|
739
|
|
|
func TestRun_FloatColumns(t *testing.T) { |
740
|
|
|
for dbType := range settings.SupportedDbTypes { |
741
|
|
|
t.Run(dbType.String(), func(t *testing.T) { |
742
|
|
|
|
743
|
|
|
s := settings.New() |
744
|
|
|
s.DbType = dbType |
745
|
|
|
db := database.New(s) |
746
|
|
|
|
747
|
|
|
columnTypes := db.GetFloatDatatypes() |
748
|
|
|
|
749
|
|
|
for _, columnType := range columnTypes { |
750
|
|
|
t.Run(columnType, func(t *testing.T) { |
751
|
|
|
|
752
|
|
|
t.Run("single table with NOT NULL column", func(t *testing.T) { |
753
|
|
|
s := settings.New() |
754
|
|
|
s.DbType = dbType |
755
|
|
|
|
756
|
|
|
mdb := newMockDb(db) |
757
|
|
|
|
758
|
|
|
table := &database.Table{ |
759
|
|
|
Name: "test_table", |
760
|
|
|
Columns: []database.Column{ |
761
|
|
|
{ |
762
|
|
|
OrdinalPosition: 1, |
763
|
|
|
Name: "column_name", |
764
|
|
|
DataType: columnType, |
765
|
|
|
}, |
766
|
|
|
}, |
767
|
|
|
} |
768
|
|
|
mdb.tables = append(mdb.tables, table) |
769
|
|
|
|
770
|
|
|
mdb. |
771
|
|
|
On("GetTables"). |
772
|
|
|
Return(mdb.tables, nil) |
773
|
|
|
mdb. |
774
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
775
|
|
|
Return(nil) |
776
|
|
|
mdb. |
777
|
|
|
On("GetColumnsOfTable", table) |
778
|
|
|
|
779
|
|
|
w := newMockWriter() |
780
|
|
|
w. |
781
|
|
|
On( |
782
|
|
|
"Write", |
783
|
|
|
"TestTable", |
784
|
|
|
"package dto\n\ntype TestTable struct {\nColumnName float64 `db:\"column_name\"`\n}", |
785
|
|
|
) |
786
|
|
|
|
787
|
|
|
err := Run(s, mdb, w) |
788
|
|
|
assert.NoError(t, err) |
789
|
|
|
}) |
790
|
|
|
|
791
|
|
|
t.Run("single table with NULL column", func(t *testing.T) { |
792
|
|
|
s := settings.New() |
793
|
|
|
s.DbType = dbType |
794
|
|
|
|
795
|
|
|
mdb := newMockDb(db) |
796
|
|
|
|
797
|
|
|
table := &database.Table{ |
798
|
|
|
Name: "test_table", |
799
|
|
|
Columns: []database.Column{ |
800
|
|
|
{ |
801
|
|
|
OrdinalPosition: 1, |
802
|
|
|
Name: "column_name", |
803
|
|
|
DataType: columnType, |
804
|
|
|
IsNullable: "YES", |
805
|
|
|
}, |
806
|
|
|
}, |
807
|
|
|
} |
808
|
|
|
mdb.tables = append(mdb.tables, table) |
809
|
|
|
|
810
|
|
|
mdb. |
811
|
|
|
On("GetTables"). |
812
|
|
|
Return(mdb.tables, nil) |
813
|
|
|
mdb. |
814
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
815
|
|
|
Return(nil) |
816
|
|
|
mdb. |
817
|
|
|
On("GetColumnsOfTable", table) |
818
|
|
|
|
819
|
|
|
w := newMockWriter() |
820
|
|
|
w. |
821
|
|
|
On( |
822
|
|
|
"Write", |
823
|
|
|
"TestTable", |
824
|
|
|
"package dto\n\nimport (\n\t\"database/sql\"\n)\n\ntype TestTable struct {\nColumnName sql.NullFloat64 `db:\"column_name\"`\n}", |
825
|
|
|
) |
826
|
|
|
|
827
|
|
|
err := Run(s, mdb, w) |
828
|
|
|
assert.NoError(t, err) |
829
|
|
|
}) |
830
|
|
|
|
831
|
|
|
t.Run("single table with NULL column and native data type", func(t *testing.T) { |
832
|
|
|
s := settings.New() |
833
|
|
|
s.DbType = dbType |
834
|
|
|
s.Null = settings.NullTypeNative |
835
|
|
|
|
836
|
|
|
mdb := newMockDb(db) |
837
|
|
|
|
838
|
|
|
table := &database.Table{ |
839
|
|
|
Name: "test_table", |
840
|
|
|
Columns: []database.Column{ |
841
|
|
|
{ |
842
|
|
|
OrdinalPosition: 1, |
843
|
|
|
Name: "column_name", |
844
|
|
|
DataType: columnType, |
845
|
|
|
IsNullable: "YES", |
846
|
|
|
}, |
847
|
|
|
}, |
848
|
|
|
} |
849
|
|
|
mdb.tables = append(mdb.tables, table) |
850
|
|
|
|
851
|
|
|
mdb. |
852
|
|
|
On("GetTables"). |
853
|
|
|
Return(mdb.tables, nil) |
854
|
|
|
mdb. |
855
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
856
|
|
|
Return(nil) |
857
|
|
|
mdb. |
858
|
|
|
On("GetColumnsOfTable", table) |
859
|
|
|
|
860
|
|
|
w := newMockWriter() |
861
|
|
|
w. |
862
|
|
|
On( |
863
|
|
|
"Write", |
864
|
|
|
"TestTable", |
865
|
|
|
"package dto\n\nimport (\n)\n\ntype TestTable struct {\nColumnName *float64 `db:\"column_name\"`\n}", |
866
|
|
|
) |
867
|
|
|
|
868
|
|
|
err := Run(s, mdb, w) |
869
|
|
|
assert.NoError(t, err) |
870
|
|
|
}) |
871
|
|
|
|
872
|
|
|
t.Run("single table with two mixed columns", func(t *testing.T) { |
873
|
|
|
s := settings.New() |
874
|
|
|
s.DbType = dbType |
875
|
|
|
|
876
|
|
|
mdb := newMockDb(db) |
877
|
|
|
|
878
|
|
|
table := &database.Table{ |
879
|
|
|
Name: "test_table", |
880
|
|
|
Columns: []database.Column{ |
881
|
|
|
{ |
882
|
|
|
OrdinalPosition: 1, |
883
|
|
|
Name: "column_name_1", |
884
|
|
|
DataType: columnType, |
885
|
|
|
IsNullable: "YES", |
886
|
|
|
}, |
887
|
|
|
{ |
888
|
|
|
OrdinalPosition: 2, |
889
|
|
|
Name: "column_name_2", |
890
|
|
|
DataType: columnType, |
891
|
|
|
}, |
892
|
|
|
}, |
893
|
|
|
} |
894
|
|
|
mdb.tables = append(mdb.tables, table) |
895
|
|
|
|
896
|
|
|
mdb. |
897
|
|
|
On("GetTables"). |
898
|
|
|
Return(mdb.tables, nil) |
899
|
|
|
mdb. |
900
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
901
|
|
|
Return(nil) |
902
|
|
|
mdb. |
903
|
|
|
On("GetColumnsOfTable", table) |
904
|
|
|
|
905
|
|
|
w := newMockWriter() |
906
|
|
|
w. |
907
|
|
|
On( |
908
|
|
|
"Write", |
909
|
|
|
"TestTable", |
910
|
|
|
"package dto\n\nimport (\n\t\"database/sql\"\n)\n\ntype TestTable struct {\nColumnName1 sql.NullFloat64 `db:\"column_name_1\"`\nColumnName2 float64 `db:\"column_name_2\"`\n}", |
911
|
|
|
) |
912
|
|
|
|
913
|
|
|
err := Run(s, mdb, w) |
914
|
|
|
assert.NoError(t, err) |
915
|
|
|
}) |
916
|
|
|
|
917
|
|
|
t.Run("single table with two mixed columns and native data type", func(t *testing.T) { |
918
|
|
|
s := settings.New() |
919
|
|
|
s.DbType = dbType |
920
|
|
|
s.Null = settings.NullTypeNative |
921
|
|
|
|
922
|
|
|
mdb := newMockDb(db) |
923
|
|
|
|
924
|
|
|
table := &database.Table{ |
925
|
|
|
Name: "test_table", |
926
|
|
|
Columns: []database.Column{ |
927
|
|
|
{ |
928
|
|
|
OrdinalPosition: 1, |
929
|
|
|
Name: "column_name_1", |
930
|
|
|
DataType: columnType, |
931
|
|
|
IsNullable: "YES", |
932
|
|
|
}, |
933
|
|
|
{ |
934
|
|
|
OrdinalPosition: 2, |
935
|
|
|
Name: "column_name_2", |
936
|
|
|
DataType: columnType, |
937
|
|
|
}, |
938
|
|
|
}, |
939
|
|
|
} |
940
|
|
|
mdb.tables = append(mdb.tables, table) |
941
|
|
|
|
942
|
|
|
mdb. |
943
|
|
|
On("GetTables"). |
944
|
|
|
Return(mdb.tables, nil) |
945
|
|
|
mdb. |
946
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
947
|
|
|
Return(nil) |
948
|
|
|
mdb. |
949
|
|
|
On("GetColumnsOfTable", table) |
950
|
|
|
|
951
|
|
|
w := newMockWriter() |
952
|
|
|
w. |
953
|
|
|
On( |
954
|
|
|
"Write", |
955
|
|
|
"TestTable", |
956
|
|
|
"package dto\n\nimport (\n)\n\ntype TestTable struct {\nColumnName1 *float64 `db:\"column_name_1\"`\nColumnName2 float64 `db:\"column_name_2\"`\n}", |
957
|
|
|
) |
958
|
|
|
|
959
|
|
|
err := Run(s, mdb, w) |
960
|
|
|
assert.NoError(t, err) |
961
|
|
|
}) |
962
|
|
|
|
963
|
|
|
t.Run("multi table with multi columns", func(t *testing.T) { |
964
|
|
|
s := settings.New() |
965
|
|
|
s.DbType = dbType |
966
|
|
|
|
967
|
|
|
mdb := newMockDb(db) |
968
|
|
|
|
969
|
|
|
table1 := &database.Table{ |
970
|
|
|
Name: "test_table_1", |
971
|
|
|
Columns: []database.Column{ |
972
|
|
|
{ |
973
|
|
|
OrdinalPosition: 1, |
974
|
|
|
Name: "column_name_1", |
975
|
|
|
DataType: columnType, |
976
|
|
|
IsNullable: "YES", |
977
|
|
|
}, |
978
|
|
|
{ |
979
|
|
|
OrdinalPosition: 2, |
980
|
|
|
Name: "column_name_2", |
981
|
|
|
DataType: columnType, |
982
|
|
|
}, |
983
|
|
|
}, |
984
|
|
|
} |
985
|
|
|
table2 := &database.Table{ |
986
|
|
|
Name: "test_table_2", |
987
|
|
|
Columns: []database.Column{ |
988
|
|
|
{ |
989
|
|
|
OrdinalPosition: 1, |
990
|
|
|
Name: "column_name_1", |
991
|
|
|
DataType: columnType, |
992
|
|
|
}, |
993
|
|
|
{ |
994
|
|
|
OrdinalPosition: 2, |
995
|
|
|
Name: "column_name_2", |
996
|
|
|
DataType: columnType, |
997
|
|
|
IsNullable: "YES", |
998
|
|
|
}, |
999
|
|
|
}, |
1000
|
|
|
} |
1001
|
|
|
mdb.tables = append(mdb.tables, table1, table2) |
1002
|
|
|
|
1003
|
|
|
mdb. |
1004
|
|
|
On("GetTables"). |
1005
|
|
|
Return(mdb.tables, nil) |
1006
|
|
|
mdb. |
1007
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
1008
|
|
|
Return(nil) |
1009
|
|
|
mdb. |
1010
|
|
|
On("GetColumnsOfTable", table1). |
1011
|
|
|
On("GetColumnsOfTable", table2) |
1012
|
|
|
|
1013
|
|
|
w := newMockWriter() |
1014
|
|
|
w. |
1015
|
|
|
On( |
1016
|
|
|
"Write", |
1017
|
|
|
"TestTable1", |
1018
|
|
|
"package dto\n\nimport (\n\t\"database/sql\"\n)\n\ntype TestTable1 struct {\nColumnName1 sql.NullFloat64 `db:\"column_name_1\"`\nColumnName2 float64 `db:\"column_name_2\"`\n}", |
1019
|
|
|
). |
1020
|
|
|
On( |
1021
|
|
|
"Write", |
1022
|
|
|
"TestTable2", |
1023
|
|
|
"package dto\n\nimport (\n\t\"database/sql\"\n)\n\ntype TestTable2 struct {\nColumnName1 float64 `db:\"column_name_1\"`\nColumnName2 sql.NullFloat64 `db:\"column_name_2\"`\n}", |
1024
|
|
|
) |
1025
|
|
|
|
1026
|
|
|
err := Run(s, mdb, w) |
1027
|
|
|
assert.NoError(t, err) |
1028
|
|
|
}) |
1029
|
|
|
}) |
1030
|
|
|
} |
1031
|
|
|
}) |
1032
|
|
|
} |
1033
|
|
|
} |
1034
|
|
|
|
1035
|
|
|
func TestRun_TemporalColumns(t *testing.T) { |
1036
|
|
|
for dbType := range settings.SupportedDbTypes { |
1037
|
|
|
t.Run(dbType.String(), func(t *testing.T) { |
1038
|
|
|
|
1039
|
|
|
s := settings.New() |
1040
|
|
|
s.DbType = dbType |
1041
|
|
|
db := database.New(s) |
1042
|
|
|
|
1043
|
|
|
columnTypes := db.GetTemporalDatatypes() |
1044
|
|
|
|
1045
|
|
|
for _, columnType := range columnTypes { |
1046
|
|
|
t.Run(columnType, func(t *testing.T) { |
1047
|
|
|
|
1048
|
|
|
t.Run("single table with NOT NULL column", func(t *testing.T) { |
1049
|
|
|
s := settings.New() |
1050
|
|
|
s.DbType = dbType |
1051
|
|
|
|
1052
|
|
|
mdb := newMockDb(db) |
1053
|
|
|
|
1054
|
|
|
table := &database.Table{ |
1055
|
|
|
Name: "test_table", |
1056
|
|
|
Columns: []database.Column{ |
1057
|
|
|
{ |
1058
|
|
|
OrdinalPosition: 1, |
1059
|
|
|
Name: "column_name", |
1060
|
|
|
DataType: columnType, |
1061
|
|
|
}, |
1062
|
|
|
}, |
1063
|
|
|
} |
1064
|
|
|
mdb.tables = append(mdb.tables, table) |
1065
|
|
|
|
1066
|
|
|
mdb. |
1067
|
|
|
On("GetTables"). |
1068
|
|
|
Return(mdb.tables, nil) |
1069
|
|
|
mdb. |
1070
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
1071
|
|
|
Return(nil) |
1072
|
|
|
mdb. |
1073
|
|
|
On("GetColumnsOfTable", table) |
1074
|
|
|
|
1075
|
|
|
w := newMockWriter() |
1076
|
|
|
w. |
1077
|
|
|
On( |
1078
|
|
|
"Write", |
1079
|
|
|
"TestTable", |
1080
|
|
|
"package dto\n\nimport (\n\t\"time\"\n)\n\ntype TestTable struct {\nColumnName time.Time `db:\"column_name\"`\n}", |
1081
|
|
|
) |
1082
|
|
|
|
1083
|
|
|
err := Run(s, mdb, w) |
1084
|
|
|
assert.NoError(t, err) |
1085
|
|
|
}) |
1086
|
|
|
|
1087
|
|
|
t.Run("single table with NULL column", func(t *testing.T) { |
1088
|
|
|
s := settings.New() |
1089
|
|
|
s.DbType = dbType |
1090
|
|
|
|
1091
|
|
|
mdb := newMockDb(db) |
1092
|
|
|
|
1093
|
|
|
table := &database.Table{ |
1094
|
|
|
Name: "test_table", |
1095
|
|
|
Columns: []database.Column{ |
1096
|
|
|
{ |
1097
|
|
|
OrdinalPosition: 1, |
1098
|
|
|
Name: "column_name", |
1099
|
|
|
DataType: columnType, |
1100
|
|
|
IsNullable: "YES", |
1101
|
|
|
}, |
1102
|
|
|
}, |
1103
|
|
|
} |
1104
|
|
|
mdb.tables = append(mdb.tables, table) |
1105
|
|
|
|
1106
|
|
|
mdb. |
1107
|
|
|
On("GetTables"). |
1108
|
|
|
Return(mdb.tables, nil) |
1109
|
|
|
mdb. |
1110
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
1111
|
|
|
Return(nil) |
1112
|
|
|
mdb. |
1113
|
|
|
On("GetColumnsOfTable", table) |
1114
|
|
|
|
1115
|
|
|
w := newMockWriter() |
1116
|
|
|
w. |
1117
|
|
|
On( |
1118
|
|
|
"Write", |
1119
|
|
|
"TestTable", |
1120
|
|
|
"package dto\n\nimport (\n\t\n"+db.GetDriverImportLibrary()+"\n)\n\ntype TestTable struct {\nColumnName "+dbType.String()+".NullTime `db:\"column_name\"`\n}", |
1121
|
|
|
) |
1122
|
|
|
|
1123
|
|
|
err := Run(s, mdb, w) |
1124
|
|
|
assert.NoError(t, err) |
1125
|
|
|
}) |
1126
|
|
|
|
1127
|
|
|
t.Run("single table with NULL column and native data type", func(t *testing.T) { |
1128
|
|
|
s := settings.New() |
1129
|
|
|
s.DbType = dbType |
1130
|
|
|
s.Null = settings.NullTypeNative |
1131
|
|
|
|
1132
|
|
|
mdb := newMockDb(db) |
1133
|
|
|
|
1134
|
|
|
table := &database.Table{ |
1135
|
|
|
Name: "test_table", |
1136
|
|
|
Columns: []database.Column{ |
1137
|
|
|
{ |
1138
|
|
|
OrdinalPosition: 1, |
1139
|
|
|
Name: "column_name", |
1140
|
|
|
DataType: columnType, |
1141
|
|
|
IsNullable: "YES", |
1142
|
|
|
}, |
1143
|
|
|
}, |
1144
|
|
|
} |
1145
|
|
|
mdb.tables = append(mdb.tables, table) |
1146
|
|
|
|
1147
|
|
|
mdb. |
1148
|
|
|
On("GetTables"). |
1149
|
|
|
Return(mdb.tables, nil) |
1150
|
|
|
mdb. |
1151
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
1152
|
|
|
Return(nil) |
1153
|
|
|
mdb. |
1154
|
|
|
On("GetColumnsOfTable", table) |
1155
|
|
|
|
1156
|
|
|
w := newMockWriter() |
1157
|
|
|
w. |
1158
|
|
|
On( |
1159
|
|
|
"Write", |
1160
|
|
|
"TestTable", |
1161
|
|
|
"package dto\n\nimport (\n\t\"time\"\n)\n\ntype TestTable struct {\nColumnName *time.Time `db:\"column_name\"`\n}", |
1162
|
|
|
) |
1163
|
|
|
|
1164
|
|
|
err := Run(s, mdb, w) |
1165
|
|
|
assert.NoError(t, err) |
1166
|
|
|
}) |
1167
|
|
|
|
1168
|
|
|
t.Run("single table with two mixed columns", func(t *testing.T) { |
1169
|
|
|
s := settings.New() |
1170
|
|
|
s.DbType = dbType |
1171
|
|
|
|
1172
|
|
|
mdb := newMockDb(db) |
1173
|
|
|
|
1174
|
|
|
table := &database.Table{ |
1175
|
|
|
Name: "test_table", |
1176
|
|
|
Columns: []database.Column{ |
1177
|
|
|
{ |
1178
|
|
|
OrdinalPosition: 1, |
1179
|
|
|
Name: "column_name_1", |
1180
|
|
|
DataType: columnType, |
1181
|
|
|
IsNullable: "YES", |
1182
|
|
|
}, |
1183
|
|
|
{ |
1184
|
|
|
OrdinalPosition: 2, |
1185
|
|
|
Name: "column_name_2", |
1186
|
|
|
DataType: columnType, |
1187
|
|
|
}, |
1188
|
|
|
}, |
1189
|
|
|
} |
1190
|
|
|
mdb.tables = append(mdb.tables, table) |
1191
|
|
|
|
1192
|
|
|
mdb. |
1193
|
|
|
On("GetTables"). |
1194
|
|
|
Return(mdb.tables, nil) |
1195
|
|
|
mdb. |
1196
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
1197
|
|
|
Return(nil) |
1198
|
|
|
mdb. |
1199
|
|
|
On("GetColumnsOfTable", table) |
1200
|
|
|
|
1201
|
|
|
w := newMockWriter() |
1202
|
|
|
w. |
1203
|
|
|
On( |
1204
|
|
|
"Write", |
1205
|
|
|
"TestTable", |
1206
|
|
|
"package dto\n\nimport (\n\t\"time\"\n\t\n"+db.GetDriverImportLibrary()+"\n)\n\ntype TestTable struct {\nColumnName1 "+dbType.String()+".NullTime `db:\"column_name_1\"`\nColumnName2 time.Time `db:\"column_name_2\"`\n}", |
1207
|
|
|
) |
1208
|
|
|
|
1209
|
|
|
err := Run(s, mdb, w) |
1210
|
|
|
assert.NoError(t, err) |
1211
|
|
|
}) |
1212
|
|
|
|
1213
|
|
|
t.Run("single table with two mixed columns and native data type", func(t *testing.T) { |
1214
|
|
|
s := settings.New() |
1215
|
|
|
s.DbType = dbType |
1216
|
|
|
s.Null = settings.NullTypeNative |
1217
|
|
|
|
1218
|
|
|
mdb := newMockDb(db) |
1219
|
|
|
|
1220
|
|
|
table := &database.Table{ |
1221
|
|
|
Name: "test_table", |
1222
|
|
|
Columns: []database.Column{ |
1223
|
|
|
{ |
1224
|
|
|
OrdinalPosition: 1, |
1225
|
|
|
Name: "column_name_1", |
1226
|
|
|
DataType: columnType, |
1227
|
|
|
IsNullable: "YES", |
1228
|
|
|
}, |
1229
|
|
|
{ |
1230
|
|
|
OrdinalPosition: 2, |
1231
|
|
|
Name: "column_name_2", |
1232
|
|
|
DataType: columnType, |
1233
|
|
|
}, |
1234
|
|
|
}, |
1235
|
|
|
} |
1236
|
|
|
mdb.tables = append(mdb.tables, table) |
1237
|
|
|
|
1238
|
|
|
mdb. |
1239
|
|
|
On("GetTables"). |
1240
|
|
|
Return(mdb.tables, nil) |
1241
|
|
|
mdb. |
1242
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
1243
|
|
|
Return(nil) |
1244
|
|
|
mdb. |
1245
|
|
|
On("GetColumnsOfTable", table) |
1246
|
|
|
|
1247
|
|
|
w := newMockWriter() |
1248
|
|
|
w. |
1249
|
|
|
On( |
1250
|
|
|
"Write", |
1251
|
|
|
"TestTable", |
1252
|
|
|
"package dto\n\nimport (\n\t\"time\"\n)\n\ntype TestTable struct {\nColumnName1 *time.Time `db:\"column_name_1\"`\nColumnName2 time.Time `db:\"column_name_2\"`\n}", |
1253
|
|
|
) |
1254
|
|
|
|
1255
|
|
|
err := Run(s, mdb, w) |
1256
|
|
|
assert.NoError(t, err) |
1257
|
|
|
}) |
1258
|
|
|
|
1259
|
|
|
t.Run("multi table with multi columns", func(t *testing.T) { |
1260
|
|
|
s := settings.New() |
1261
|
|
|
s.DbType = dbType |
1262
|
|
|
|
1263
|
|
|
mdb := newMockDb(db) |
1264
|
|
|
|
1265
|
|
|
table1 := &database.Table{ |
1266
|
|
|
Name: "test_table_1", |
1267
|
|
|
Columns: []database.Column{ |
1268
|
|
|
{ |
1269
|
|
|
OrdinalPosition: 1, |
1270
|
|
|
Name: "column_name_1", |
1271
|
|
|
DataType: columnType, |
1272
|
|
|
IsNullable: "YES", |
1273
|
|
|
}, |
1274
|
|
|
{ |
1275
|
|
|
OrdinalPosition: 2, |
1276
|
|
|
Name: "column_name_2", |
1277
|
|
|
DataType: columnType, |
1278
|
|
|
}, |
1279
|
|
|
}, |
1280
|
|
|
} |
1281
|
|
|
table2 := &database.Table{ |
1282
|
|
|
Name: "test_table_2", |
1283
|
|
|
Columns: []database.Column{ |
1284
|
|
|
{ |
1285
|
|
|
OrdinalPosition: 1, |
1286
|
|
|
Name: "column_name_1", |
1287
|
|
|
DataType: columnType, |
1288
|
|
|
}, |
1289
|
|
|
{ |
1290
|
|
|
OrdinalPosition: 2, |
1291
|
|
|
Name: "column_name_2", |
1292
|
|
|
DataType: columnType, |
1293
|
|
|
IsNullable: "YES", |
1294
|
|
|
}, |
1295
|
|
|
}, |
1296
|
|
|
} |
1297
|
|
|
mdb.tables = append(mdb.tables, table1, table2) |
1298
|
|
|
|
1299
|
|
|
mdb. |
1300
|
|
|
On("GetTables"). |
1301
|
|
|
Return(mdb.tables, nil) |
1302
|
|
|
mdb. |
1303
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
1304
|
|
|
Return(nil) |
1305
|
|
|
mdb. |
1306
|
|
|
On("GetColumnsOfTable", table1). |
1307
|
|
|
On("GetColumnsOfTable", table2) |
1308
|
|
|
|
1309
|
|
|
w := newMockWriter() |
1310
|
|
|
w. |
1311
|
|
|
On( |
1312
|
|
|
"Write", |
1313
|
|
|
"TestTable1", |
1314
|
|
|
"package dto\n\nimport (\n\t\"time\"\n\t\n"+db.GetDriverImportLibrary()+"\n)\n\ntype TestTable1 struct {\nColumnName1 "+dbType.String()+".NullTime `db:\"column_name_1\"`\nColumnName2 time.Time `db:\"column_name_2\"`\n}", |
1315
|
|
|
). |
1316
|
|
|
On( |
1317
|
|
|
"Write", |
1318
|
|
|
"TestTable2", |
1319
|
|
|
"package dto\n\nimport (\n\t\"time\"\n\t\n"+db.GetDriverImportLibrary()+"\n)\n\ntype TestTable2 struct {\nColumnName1 time.Time `db:\"column_name_1\"`\nColumnName2 "+dbType.String()+".NullTime `db:\"column_name_2\"`\n}", |
1320
|
|
|
) |
1321
|
|
|
|
1322
|
|
|
err := Run(s, mdb, w) |
1323
|
|
|
assert.NoError(t, err) |
1324
|
|
|
}) |
1325
|
|
|
}) |
1326
|
|
|
} |
1327
|
|
|
}) |
1328
|
|
|
} |
1329
|
|
|
} |
1330
|
|
|
|
1331
|
|
|
func TestRun_BooleanColumns(t *testing.T) { |
1332
|
|
|
for dbType := range settings.SupportedDbTypes { |
1333
|
|
|
t.Run(dbType.String(), func(t *testing.T) { |
1334
|
|
|
|
1335
|
|
|
s := settings.New() |
1336
|
|
|
s.DbType = dbType |
1337
|
|
|
db := database.New(s) |
1338
|
|
|
|
1339
|
|
|
columnTypes := []string{"boolean"} |
1340
|
|
|
|
1341
|
|
|
for _, columnType := range columnTypes { |
1342
|
|
|
t.Run(columnType, func(t *testing.T) { |
1343
|
|
|
|
1344
|
|
|
t.Run("single table with NOT NULL column", func(t *testing.T) { |
1345
|
|
|
s := settings.New() |
1346
|
|
|
s.DbType = dbType |
1347
|
|
|
|
1348
|
|
|
mdb := newMockDb(db) |
1349
|
|
|
|
1350
|
|
|
table := &database.Table{ |
1351
|
|
|
Name: "test_table", |
1352
|
|
|
Columns: []database.Column{ |
1353
|
|
|
{ |
1354
|
|
|
OrdinalPosition: 1, |
1355
|
|
|
Name: "column_name", |
1356
|
|
|
DataType: columnType, |
1357
|
|
|
}, |
1358
|
|
|
}, |
1359
|
|
|
} |
1360
|
|
|
mdb.tables = append(mdb.tables, table) |
1361
|
|
|
|
1362
|
|
|
mdb. |
1363
|
|
|
On("GetTables"). |
1364
|
|
|
Return(mdb.tables, nil) |
1365
|
|
|
mdb. |
1366
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
1367
|
|
|
Return(nil) |
1368
|
|
|
mdb. |
1369
|
|
|
On("GetColumnsOfTable", table) |
1370
|
|
|
|
1371
|
|
|
w := newMockWriter() |
1372
|
|
|
w. |
1373
|
|
|
On( |
1374
|
|
|
"Write", |
1375
|
|
|
"TestTable", |
1376
|
|
|
"package dto\n\ntype TestTable struct {\nColumnName bool `db:\"column_name\"`\n}", |
1377
|
|
|
) |
1378
|
|
|
|
1379
|
|
|
err := Run(s, mdb, w) |
1380
|
|
|
assert.NoError(t, err) |
1381
|
|
|
}) |
1382
|
|
|
|
1383
|
|
|
t.Run("single table with NULL column", func(t *testing.T) { |
1384
|
|
|
s := settings.New() |
1385
|
|
|
s.DbType = dbType |
1386
|
|
|
|
1387
|
|
|
mdb := newMockDb(db) |
1388
|
|
|
|
1389
|
|
|
table := &database.Table{ |
1390
|
|
|
Name: "test_table", |
1391
|
|
|
Columns: []database.Column{ |
1392
|
|
|
{ |
1393
|
|
|
OrdinalPosition: 1, |
1394
|
|
|
Name: "column_name", |
1395
|
|
|
DataType: columnType, |
1396
|
|
|
IsNullable: "YES", |
1397
|
|
|
}, |
1398
|
|
|
}, |
1399
|
|
|
} |
1400
|
|
|
mdb.tables = append(mdb.tables, table) |
1401
|
|
|
|
1402
|
|
|
mdb. |
1403
|
|
|
On("GetTables"). |
1404
|
|
|
Return(mdb.tables, nil) |
1405
|
|
|
mdb. |
1406
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
1407
|
|
|
Return(nil) |
1408
|
|
|
mdb. |
1409
|
|
|
On("GetColumnsOfTable", table) |
1410
|
|
|
|
1411
|
|
|
w := newMockWriter() |
1412
|
|
|
w. |
1413
|
|
|
On( |
1414
|
|
|
"Write", |
1415
|
|
|
"TestTable", |
1416
|
|
|
"package dto\n\nimport (\n\t\"database/sql\"\n)\n\ntype TestTable struct {\nColumnName sql.NullBool `db:\"column_name\"`\n}", |
1417
|
|
|
) |
1418
|
|
|
|
1419
|
|
|
err := Run(s, mdb, w) |
1420
|
|
|
assert.NoError(t, err) |
1421
|
|
|
}) |
1422
|
|
|
|
1423
|
|
|
t.Run("single table with NULL column and native data type", func(t *testing.T) { |
1424
|
|
|
s := settings.New() |
1425
|
|
|
s.DbType = dbType |
1426
|
|
|
s.Null = settings.NullTypeNative |
1427
|
|
|
|
1428
|
|
|
mdb := newMockDb(db) |
1429
|
|
|
|
1430
|
|
|
table := &database.Table{ |
1431
|
|
|
Name: "test_table", |
1432
|
|
|
Columns: []database.Column{ |
1433
|
|
|
{ |
1434
|
|
|
OrdinalPosition: 1, |
1435
|
|
|
Name: "column_name", |
1436
|
|
|
DataType: columnType, |
1437
|
|
|
IsNullable: "YES", |
1438
|
|
|
}, |
1439
|
|
|
}, |
1440
|
|
|
} |
1441
|
|
|
mdb.tables = append(mdb.tables, table) |
1442
|
|
|
|
1443
|
|
|
mdb. |
1444
|
|
|
On("GetTables"). |
1445
|
|
|
Return(mdb.tables, nil) |
1446
|
|
|
mdb. |
1447
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
1448
|
|
|
Return(nil) |
1449
|
|
|
mdb. |
1450
|
|
|
On("GetColumnsOfTable", table) |
1451
|
|
|
|
1452
|
|
|
w := newMockWriter() |
1453
|
|
|
w. |
1454
|
|
|
On( |
1455
|
|
|
"Write", |
1456
|
|
|
"TestTable", |
1457
|
|
|
"package dto\n\nimport (\n)\n\ntype TestTable struct {\nColumnName *bool `db:\"column_name\"`\n}", |
1458
|
|
|
) |
1459
|
|
|
|
1460
|
|
|
err := Run(s, mdb, w) |
1461
|
|
|
assert.NoError(t, err) |
1462
|
|
|
}) |
1463
|
|
|
|
1464
|
|
|
t.Run("single table with two mixed columns", func(t *testing.T) { |
1465
|
|
|
s := settings.New() |
1466
|
|
|
s.DbType = dbType |
1467
|
|
|
|
1468
|
|
|
mdb := newMockDb(db) |
1469
|
|
|
|
1470
|
|
|
table := &database.Table{ |
1471
|
|
|
Name: "test_table", |
1472
|
|
|
Columns: []database.Column{ |
1473
|
|
|
{ |
1474
|
|
|
OrdinalPosition: 1, |
1475
|
|
|
Name: "column_name_1", |
1476
|
|
|
DataType: columnType, |
1477
|
|
|
IsNullable: "YES", |
1478
|
|
|
}, |
1479
|
|
|
{ |
1480
|
|
|
OrdinalPosition: 2, |
1481
|
|
|
Name: "column_name_2", |
1482
|
|
|
DataType: columnType, |
1483
|
|
|
}, |
1484
|
|
|
}, |
1485
|
|
|
} |
1486
|
|
|
mdb.tables = append(mdb.tables, table) |
1487
|
|
|
|
1488
|
|
|
mdb. |
1489
|
|
|
On("GetTables"). |
1490
|
|
|
Return(mdb.tables, nil) |
1491
|
|
|
mdb. |
1492
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
1493
|
|
|
Return(nil) |
1494
|
|
|
mdb. |
1495
|
|
|
On("GetColumnsOfTable", table) |
1496
|
|
|
|
1497
|
|
|
w := newMockWriter() |
1498
|
|
|
w. |
1499
|
|
|
On( |
1500
|
|
|
"Write", |
1501
|
|
|
"TestTable", |
1502
|
|
|
"package dto\n\nimport (\n\t\"database/sql\"\n)\n\ntype TestTable struct {\nColumnName1 sql.NullBool `db:\"column_name_1\"`\nColumnName2 bool `db:\"column_name_2\"`\n}", |
1503
|
|
|
) |
1504
|
|
|
|
1505
|
|
|
err := Run(s, mdb, w) |
1506
|
|
|
assert.NoError(t, err) |
1507
|
|
|
}) |
1508
|
|
|
|
1509
|
|
|
t.Run("single table with two mixed columns and native data type", func(t *testing.T) { |
1510
|
|
|
s := settings.New() |
1511
|
|
|
s.DbType = dbType |
1512
|
|
|
s.Null = settings.NullTypeNative |
1513
|
|
|
|
1514
|
|
|
mdb := newMockDb(db) |
1515
|
|
|
|
1516
|
|
|
table := &database.Table{ |
1517
|
|
|
Name: "test_table", |
1518
|
|
|
Columns: []database.Column{ |
1519
|
|
|
{ |
1520
|
|
|
OrdinalPosition: 1, |
1521
|
|
|
Name: "column_name_1", |
1522
|
|
|
DataType: columnType, |
1523
|
|
|
IsNullable: "YES", |
1524
|
|
|
}, |
1525
|
|
|
{ |
1526
|
|
|
OrdinalPosition: 2, |
1527
|
|
|
Name: "column_name_2", |
1528
|
|
|
DataType: columnType, |
1529
|
|
|
}, |
1530
|
|
|
}, |
1531
|
|
|
} |
1532
|
|
|
mdb.tables = append(mdb.tables, table) |
1533
|
|
|
|
1534
|
|
|
mdb. |
1535
|
|
|
On("GetTables"). |
1536
|
|
|
Return(mdb.tables, nil) |
1537
|
|
|
mdb. |
1538
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
1539
|
|
|
Return(nil) |
1540
|
|
|
mdb. |
1541
|
|
|
On("GetColumnsOfTable", table) |
1542
|
|
|
|
1543
|
|
|
w := newMockWriter() |
1544
|
|
|
w. |
1545
|
|
|
On( |
1546
|
|
|
"Write", |
1547
|
|
|
"TestTable", |
1548
|
|
|
"package dto\n\nimport (\n)\n\ntype TestTable struct {\nColumnName1 *bool `db:\"column_name_1\"`\nColumnName2 bool `db:\"column_name_2\"`\n}", |
1549
|
|
|
) |
1550
|
|
|
|
1551
|
|
|
err := Run(s, mdb, w) |
1552
|
|
|
assert.NoError(t, err) |
1553
|
|
|
}) |
1554
|
|
|
|
1555
|
|
|
t.Run("multi table with multi columns", func(t *testing.T) { |
1556
|
|
|
s := settings.New() |
1557
|
|
|
s.DbType = dbType |
1558
|
|
|
|
1559
|
|
|
mdb := newMockDb(db) |
1560
|
|
|
|
1561
|
|
|
table1 := &database.Table{ |
1562
|
|
|
Name: "test_table_1", |
1563
|
|
|
Columns: []database.Column{ |
1564
|
|
|
{ |
1565
|
|
|
OrdinalPosition: 1, |
1566
|
|
|
Name: "column_name_1", |
1567
|
|
|
DataType: columnType, |
1568
|
|
|
IsNullable: "YES", |
1569
|
|
|
}, |
1570
|
|
|
{ |
1571
|
|
|
OrdinalPosition: 2, |
1572
|
|
|
Name: "column_name_2", |
1573
|
|
|
DataType: columnType, |
1574
|
|
|
}, |
1575
|
|
|
}, |
1576
|
|
|
} |
1577
|
|
|
table2 := &database.Table{ |
1578
|
|
|
Name: "test_table_2", |
1579
|
|
|
Columns: []database.Column{ |
1580
|
|
|
{ |
1581
|
|
|
OrdinalPosition: 1, |
1582
|
|
|
Name: "column_name_1", |
1583
|
|
|
DataType: columnType, |
1584
|
|
|
}, |
1585
|
|
|
{ |
1586
|
|
|
OrdinalPosition: 2, |
1587
|
|
|
Name: "column_name_2", |
1588
|
|
|
DataType: columnType, |
1589
|
|
|
IsNullable: "YES", |
1590
|
|
|
}, |
1591
|
|
|
}, |
1592
|
|
|
} |
1593
|
|
|
mdb.tables = append(mdb.tables, table1, table2) |
1594
|
|
|
|
1595
|
|
|
mdb. |
1596
|
|
|
On("GetTables"). |
1597
|
|
|
Return(mdb.tables, nil) |
1598
|
|
|
mdb. |
1599
|
|
|
On("PrepareGetColumnsOfTableStmt"). |
1600
|
|
|
Return(nil) |
1601
|
|
|
mdb. |
1602
|
|
|
On("GetColumnsOfTable", table1). |
1603
|
|
|
On("GetColumnsOfTable", table2) |
1604
|
|
|
|
1605
|
|
|
w := newMockWriter() |
1606
|
|
|
w. |
1607
|
|
|
On( |
1608
|
|
|
"Write", |
1609
|
|
|
"TestTable1", |
1610
|
|
|
"package dto\n\nimport (\n\t\"database/sql\"\n)\n\ntype TestTable1 struct {\nColumnName1 sql.NullBool `db:\"column_name_1\"`\nColumnName2 bool `db:\"column_name_2\"`\n}", |
1611
|
|
|
). |
1612
|
|
|
On( |
1613
|
|
|
"Write", |
1614
|
|
|
"TestTable2", |
1615
|
|
|
"package dto\n\nimport (\n\t\"database/sql\"\n)\n\ntype TestTable2 struct {\nColumnName1 bool `db:\"column_name_1\"`\nColumnName2 sql.NullBool `db:\"column_name_2\"`\n}", |
1616
|
|
|
) |
1617
|
|
|
|
1618
|
|
|
err := Run(s, mdb, w) |
1619
|
|
|
assert.NoError(t, err) |
1620
|
|
|
}) |
1621
|
|
|
}) |
1622
|
|
|
} |
1623
|
|
|
}) |
1624
|
|
|
} |
1625
|
|
|
} |
1626
|
|
|
|