@@ -64,6 +64,15 @@ describe('postgresql connector', function() {
6464 loc : 'GeoPoint' ,
6565 created : Date ,
6666 approved : Boolean ,
67+ tags : {
68+ type : [ 'string' ] ,
69+ } ,
70+ categories : {
71+ type : [ 'string' ] ,
72+ postgresql : {
73+ dataType : 'varchar[]' ,
74+ } ,
75+ } ,
6776 } ) ;
6877 created = new Date ( ) ;
6978 } ) ;
@@ -201,6 +210,59 @@ describe('postgresql connector', function() {
201210 } ) ;
202211 } ) ;
203212
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+
204266 it ( 'should support boolean types with false value' , function ( done ) {
205267 Post . create (
206268 { title : 'T2' , content : 'C2' , approved : false , created : created } ,
0 commit comments