Skip to content

Commit 5a5d62f

Browse files
committed
array_type_field_filter: Added new contains filter to search on Array type field
Signed-off-by: shubhisood <[email protected]>
1 parent ced6c28 commit 5a5d62f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/postgresql.js

+3
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,9 @@ PostgreSQL.prototype.buildExpression = function(columnName, operator,
522522
const regexOperator = operatorValue.ignoreCase ? ' ~* ?' : ' ~ ?';
523523
return new ParameterizedSQL(columnName + regexOperator,
524524
[operatorValue.source]);
525+
case 'contains':
526+
return new ParameterizedSQL(columnName + ' @> array[' + operatorValue.map((v) => `'${v}'`) + ']::'
527+
+ propertyDefinition.postgresql.dataType);
525528
default:
526529
// invoke the base implementation of `buildExpression`
527530
return this.invokeSuper('buildExpression', columnName, operator,

test/postgresql.test.js

+11
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,17 @@ describe('postgresql connector', function() {
263263
});
264264
});
265265

266+
it('should support where filter for array type field', function(done) {
267+
Post.find({where: {and: [
268+
{
269+
categories: {contains: ['AA']},
270+
},
271+
]}}, function(err, post) {
272+
should.not.exist(err);
273+
should.exist(post);
274+
done();
275+
});
276+
});
266277
it('should support boolean types with false value', function(done) {
267278
Post.create(
268279
{title: 'T2', content: 'C2', approved: false, created: created},

0 commit comments

Comments
 (0)