@@ -64,6 +64,15 @@ describe('postgresql connector', function() {
64
64
loc : 'GeoPoint' ,
65
65
created : Date ,
66
66
approved : Boolean ,
67
+ tags : {
68
+ type : [ 'string' ] ,
69
+ } ,
70
+ categories : {
71
+ type : [ 'string' ] ,
72
+ postgresql : {
73
+ dataType : 'varchar[]' ,
74
+ } ,
75
+ } ,
67
76
} ) ;
68
77
created = new Date ( ) ;
69
78
} ) ;
@@ -201,6 +210,59 @@ describe('postgresql connector', function() {
201
210
} ) ;
202
211
} ) ;
203
212
213
+ it ( 'should support creating and updating arrays with default dataType' , function ( done ) {
214
+ let postId ;
215
+ Post . create ( { title : 'Updating Arrays' , content : 'Content' , tags : [ 'AA' , 'AB' ] } )
216
+ . then ( ( post ) => {
217
+ postId = post . id ;
218
+ post . should . have . property ( 'tags' ) ;
219
+ post . tags . should . be . Array ( ) ;
220
+ post . tags . length . should . eql ( 2 ) ;
221
+ post . tags . should . eql ( [ 'AA' , 'AB' ] ) ;
222
+ return Post . updateAll ( { where : { id : postId } } , { tags : [ 'AA' , 'AC' ] } ) ;
223
+ } )
224
+ . then ( ( ) => {
225
+ return Post . findOne ( { where : { id : postId } } ) ;
226
+ } )
227
+ . then ( ( post ) => {
228
+ post . should . have . property ( 'tags' ) ;
229
+ post . tags . should . be . Array ( ) ;
230
+ post . tags . length . should . eql ( 2 ) ;
231
+ post . tags . should . eql ( [ 'AA' , 'AC' ] ) ;
232
+ done ( ) ;
233
+ } )
234
+ . catch ( ( error ) => {
235
+ done ( error ) ;
236
+ } ) ;
237
+ } ) ;
238
+
239
+ it ( 'should support creating and updating arrays with "varchar[]" dataType' , function ( done ) {
240
+ let postId ;
241
+ Post . create ( { title : 'Updating Arrays' , content : 'Content' , categories : [ 'AA' , 'AB' ] } )
242
+ . then ( ( post ) => {
243
+ postId = post . id ;
244
+ post . should . have . property ( 'categories' ) ;
245
+ post . should . have . property ( 'categories' ) ;
246
+ post . categories . should . be . Array ( ) ;
247
+ post . categories . length . should . eql ( 2 ) ;
248
+ post . categories . should . eql ( [ 'AA' , 'AB' ] ) ;
249
+ return Post . updateAll ( { where : { id : postId } } , { categories : [ 'AA' , 'AC' ] } ) ;
250
+ } )
251
+ . then ( ( ) => {
252
+ return Post . findOne ( { where : { id : postId } } ) ;
253
+ } )
254
+ . then ( ( post ) => {
255
+ post . should . have . property ( 'categories' ) ;
256
+ post . categories . should . be . Array ( ) ;
257
+ post . categories . length . should . eql ( 2 ) ;
258
+ post . categories . should . eql ( [ 'AA' , 'AC' ] ) ;
259
+ done ( ) ;
260
+ } )
261
+ . catch ( ( error ) => {
262
+ done ( error ) ;
263
+ } ) ;
264
+ } ) ;
265
+
204
266
it ( 'should support boolean types with false value' , function ( done ) {
205
267
Post . create (
206
268
{ title : 'T2' , content : 'C2' , approved : false , created : created } ,
0 commit comments