@@ -109,6 +109,214 @@ func TestTimestampsColumn(t *testing.T) {
109
109
assert .Equal (Timable {Type : "timestamp" , Default : "CURRENT_TIMESTAMP" , OnUpdate : "CURRENT_TIMESTAMP" }, table .columns [1 ].definition )
110
110
}
111
111
112
+ func TestIntColumn (t * testing.T ) {
113
+ assert := assert .New (t )
114
+ table := Table {}
115
+
116
+ assert .Nil (table .columns )
117
+
118
+ table .Int ("number" , 64 , true )
119
+
120
+ assert .Len (table .columns , 1 )
121
+ assert .Equal ("number" , table .columns [0 ].field )
122
+ assert .Equal (Integer {Precision : 64 , Unsigned : true }, table .columns [0 ].definition )
123
+ }
124
+
125
+ func TestBigIntColumn (t * testing.T ) {
126
+ assert := assert .New (t )
127
+ table := Table {}
128
+
129
+ assert .Nil (table .columns )
130
+
131
+ table .BigInt ("number" , 64 , true )
132
+
133
+ assert .Len (table .columns , 1 )
134
+ assert .Equal ("number" , table .columns [0 ].field )
135
+ assert .Equal (Integer {Prefix : "big" , Precision : 64 , Unsigned : true }, table .columns [0 ].definition )
136
+ }
137
+
138
+ func TestFloatColumn (t * testing.T ) {
139
+ assert := assert .New (t )
140
+ table := Table {}
141
+
142
+ assert .Nil (table .columns )
143
+
144
+ table .Float ("number" , 15 , 2 )
145
+
146
+ assert .Len (table .columns , 1 )
147
+ assert .Equal ("number" , table .columns [0 ].field )
148
+ assert .Equal (Floatable {Precision : 15 , Scale : 2 }, table .columns [0 ].definition )
149
+ }
150
+
151
+ func TestFixedFloatColumn (t * testing.T ) {
152
+ assert := assert .New (t )
153
+ table := Table {}
154
+
155
+ assert .Nil (table .columns )
156
+
157
+ table .FixedFloat ("number" , 15 , 2 )
158
+
159
+ assert .Len (table .columns , 1 )
160
+ assert .Equal ("number" , table .columns [0 ].field )
161
+ assert .Equal (Floatable {Type : "decimal" , Precision : 15 , Scale : 2 }, table .columns [0 ].definition )
162
+ }
163
+
164
+ func TestDecimalColumn (t * testing.T ) {
165
+ assert := assert .New (t )
166
+ table := Table {}
167
+
168
+ assert .Nil (table .columns )
169
+
170
+ table .Decimal ("number" , 15 , 2 )
171
+
172
+ assert .Len (table .columns , 1 )
173
+ assert .Equal ("number" , table .columns [0 ].field )
174
+ assert .Equal (Floatable {Type : "decimal" , Precision : 15 , Scale : 2 }, table .columns [0 ].definition )
175
+ }
176
+
177
+ func TestVarcharColumn (t * testing.T ) {
178
+ assert := assert .New (t )
179
+ table := Table {}
180
+
181
+ assert .Nil (table .columns )
182
+
183
+ table .Varchar ("string" , 64 )
184
+
185
+ assert .Len (table .columns , 1 )
186
+ assert .Equal ("string" , table .columns [0 ].field )
187
+ assert .Equal (String {Precision : 64 }, table .columns [0 ].definition )
188
+ }
189
+
190
+ func TestCharColumn (t * testing.T ) {
191
+ assert := assert .New (t )
192
+ table := Table {}
193
+
194
+ assert .Nil (table .columns )
195
+
196
+ table .Char ("string" , 32 )
197
+
198
+ assert .Len (table .columns , 1 )
199
+ assert .Equal ("string" , table .columns [0 ].field )
200
+ assert .Equal (String {Fixed : true , Precision : 32 }, table .columns [0 ].definition )
201
+ }
202
+
203
+ func TestTextColumn (t * testing.T ) {
204
+ assert := assert .New (t )
205
+ table := Table {}
206
+
207
+ assert .Nil (table .columns )
208
+
209
+ table .Text ("string" , true )
210
+
211
+ assert .Len (table .columns , 1 )
212
+ assert .Equal ("string" , table .columns [0 ].field )
213
+ assert .Equal (Text {Nullable : true }, table .columns [0 ].definition )
214
+ }
215
+
216
+ func TestBlobColumn (t * testing.T ) {
217
+ assert := assert .New (t )
218
+ table := Table {}
219
+
220
+ assert .Nil (table .columns )
221
+
222
+ table .Blob ("string" , true )
223
+
224
+ assert .Len (table .columns , 1 )
225
+ assert .Equal ("string" , table .columns [0 ].field )
226
+ assert .Equal (Text {Blob : true , Nullable : true }, table .columns [0 ].definition )
227
+ }
228
+
229
+ func TestJsonColumn (t * testing.T ) {
230
+ assert := assert .New (t )
231
+ table := Table {}
232
+
233
+ assert .Nil (table .columns )
234
+
235
+ table .JSON ("data" )
236
+
237
+ assert .Len (table .columns , 1 )
238
+ assert .Equal ("data" , table .columns [0 ].field )
239
+ assert .Equal (JSON {}, table .columns [0 ].definition )
240
+ }
241
+
242
+ func TestTimestampColumn (t * testing.T ) {
243
+ assert := assert .New (t )
244
+ table := Table {}
245
+
246
+ assert .Nil (table .columns )
247
+
248
+ table .Timestamp ("date" , true , "CURRENT_TIMESTAMP" )
249
+
250
+ assert .Len (table .columns , 1 )
251
+ assert .Equal ("date" , table .columns [0 ].field )
252
+ assert .Equal (Timable {Nullable : true , Default : "CURRENT_TIMESTAMP" }, table .columns [0 ].definition )
253
+ }
254
+
255
+ func TestDateColumn (t * testing.T ) {
256
+ assert := assert .New (t )
257
+ table := Table {}
258
+
259
+ assert .Nil (table .columns )
260
+
261
+ table .Date ("date" , true , "NOW()" )
262
+
263
+ assert .Len (table .columns , 1 )
264
+ assert .Equal ("date" , table .columns [0 ].field )
265
+ assert .Equal (Timable {Type : "date" , Nullable : true , Default : "NOW()" }, table .columns [0 ].definition )
266
+ }
267
+
268
+ func TestTimeColumn (t * testing.T ) {
269
+ assert := assert .New (t )
270
+ table := Table {}
271
+
272
+ assert .Nil (table .columns )
273
+
274
+ table .Time ("time" , true , "NOW()" )
275
+
276
+ assert .Len (table .columns , 1 )
277
+ assert .Equal ("time" , table .columns [0 ].field )
278
+ assert .Equal (Timable {Type : "time" , Nullable : true , Default : "NOW()" }, table .columns [0 ].definition )
279
+ }
280
+
281
+ func TestYearColumn (t * testing.T ) {
282
+ assert := assert .New (t )
283
+ table := Table {}
284
+
285
+ assert .Nil (table .columns )
286
+
287
+ table .Year ("year" , true , "YEAR(NOW())" )
288
+
289
+ assert .Len (table .columns , 1 )
290
+ assert .Equal ("year" , table .columns [0 ].field )
291
+ assert .Equal (Timable {Type : "year" , Nullable : true , Default : "YEAR(NOW())" }, table .columns [0 ].definition )
292
+ }
293
+
294
+ func TestBinaryColumn (t * testing.T ) {
295
+ assert := assert .New (t )
296
+ table := Table {}
297
+
298
+ assert .Nil (table .columns )
299
+
300
+ table .Binary ("binary" , 36 , true )
301
+
302
+ assert .Len (table .columns , 1 )
303
+ assert .Equal ("binary" , table .columns [0 ].field )
304
+ assert .Equal (Binary {Fixed : true , Precision : 36 , Nullable : true }, table .columns [0 ].definition )
305
+ }
306
+
307
+ func TestVarbinaryColumn (t * testing.T ) {
308
+ assert := assert .New (t )
309
+ table := Table {}
310
+
311
+ assert .Nil (table .columns )
312
+
313
+ table .Varbinary ("binary" , 36 , true )
314
+
315
+ assert .Len (table .columns , 1 )
316
+ assert .Equal ("binary" , table .columns [0 ].field )
317
+ assert .Equal (Binary {Precision : 36 , Nullable : true }, table .columns [0 ].definition )
318
+ }
319
+
112
320
func TestTablePrimaryIndex (t * testing.T ) {
113
321
t .Run ("it skips adding key on empty columns list" , func (t * testing.T ) {
114
322
assert := assert .New (t )
0 commit comments