@@ -169,6 +169,141 @@ describe('PostgreSQL dialect', function() {
169169 } ) ;
170170 } ) ;
171171
172+ describe ( 'array' , function ( ) {
173+ it ( 'should replace empty array to {}' , function ( ) {
174+ var result = jsonSql . build ( {
175+ table : 'test' ,
176+ condition : {
177+ 'params' : [ ]
178+ }
179+ } ) ;
180+
181+ expect ( result . query ) . to . be . equal (
182+ 'select * from "test" where "params" = $1;'
183+ ) ;
184+ expect ( result . values ) . to . be . eql ( [ '{}' ] ) ;
185+ } ) ;
186+
187+ it ( 'should be ok with empty array in modification' , function ( ) {
188+ var result = jsonSql . build ( {
189+ type : 'update' ,
190+ table : 'test' ,
191+ modifier : {
192+ 'params' : [ ]
193+ }
194+ } ) ;
195+
196+ expect ( result . query ) . to . be . equal ( 'update "test" set "params" = $1;' ) ;
197+ expect ( result . values ) . to . be . eql ( [ '{}' ] ) ;
198+ } ) ;
199+
200+ it ( 'should be ok with empty array in values' , function ( ) {
201+ var result = jsonSql . build ( {
202+ type : 'insert' ,
203+ table : 'test' ,
204+ values : {
205+ 'params' : [ ]
206+ }
207+ } ) ;
208+
209+ expect ( result . query ) . to . be . equal ( 'insert into "test" ("params") values ($1);' ) ;
210+ expect ( result . values ) . to . be . eql ( [ '{}' ] ) ;
211+ } ) ;
212+
213+ it ( 'should be ok with `$arrayContains` conditional operator' , function ( ) {
214+ var result = jsonSql . build ( {
215+ table : 'test' ,
216+ condition : {
217+ 'params' : {
218+ $arrayContains : [ 'a' ]
219+ }
220+ }
221+ } ) ;
222+
223+ expect ( result . query ) . to . be . equal (
224+ 'select * from "test" where "params" @> array[$1];'
225+ ) ;
226+ expect ( result . values ) . to . be . eql ( [ 'a' ] ) ;
227+ } ) ;
228+
229+ it ( 'should correctly wrap `$arrayContains` parameters to array' , function ( ) {
230+ var result = jsonSql . build ( {
231+ table : 'test' ,
232+ condition : {
233+ 'params' : {
234+ $arrayContains : 'a'
235+ }
236+ }
237+ } ) ;
238+
239+ expect ( result . query ) . to . be . equal (
240+ 'select * from "test" where "params" @> array[$1];'
241+ ) ;
242+ expect ( result . values ) . to . be . eql ( [ 'a' ] ) ;
243+ } ) ;
244+
245+ it ( 'should be ok with `$arrayIn` conditional operator' , function ( ) {
246+ var result = jsonSql . build ( {
247+ table : 'test' ,
248+ condition : {
249+ 'params' : {
250+ $arrayIn : [ 'a' ]
251+ }
252+ }
253+ } ) ;
254+
255+ expect ( result . query ) . to . be . equal (
256+ 'select * from "test" where "params" <@ array[$1];'
257+ ) ;
258+ expect ( result . values ) . to . be . eql ( [ 'a' ] ) ;
259+ } ) ;
260+
261+ it ( 'should correctly wrap `$arrayIn` parameters to array' , function ( ) {
262+ var result = jsonSql . build ( {
263+ table : 'test' ,
264+ condition : {
265+ 'params' : {
266+ $arrayIn : 'a'
267+ }
268+ }
269+ } ) ;
270+
271+ expect ( result . query ) . to . be . equal (
272+ 'select * from "test" where "params" <@ array[$1];'
273+ ) ;
274+ expect ( result . values ) . to . be . eql ( [ 'a' ] ) ;
275+ } ) ;
276+
277+ it ( 'should be ok with `$arrayOverlap` conditional operator' , function ( ) {
278+ var result = jsonSql . build ( {
279+ table : 'test' ,
280+ condition : {
281+ params : {
282+ $arrayOverlap : [ 'a' ]
283+ }
284+ }
285+ } ) ;
286+
287+ expect ( result . query ) . to . be . equal ( 'select * from "test" where "params" && array[$1];' ) ;
288+ expect ( result . values ) . to . be . eql ( [ 'a' ] ) ;
289+ } ) ;
290+
291+ it ( 'should correctly wrap `$arrayOverlap` parameters to array' , function ( ) {
292+ var result = jsonSql . build ( {
293+ table : 'test' ,
294+ condition : {
295+ params : {
296+ $arrayOverlap : 'a'
297+ }
298+ }
299+ } ) ;
300+
301+ expect ( result . query ) . to . be . equal ( 'select * from "test" where "params" && array[$1];' ) ;
302+ expect ( result . values ) . to . be . eql ( [ 'a' ] ) ;
303+ } ) ;
304+ } ) ;
305+
306+
172307 describe ( 'explain' , function ( ) {
173308 it ( 'should throw error without `query`, `select` and `expression` properties' ,
174309 function ( ) {
0 commit comments