Skip to content

Commit 5fc5d1e

Browse files
committed
array_type_field_filter: Adds 'contains' operator.
1. Adds filter for array type field. 2. From this operator filter you can search array type field. Signed-off-by: shubhisood <[email protected]>
1 parent ced6c28 commit 5fc5d1e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-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

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

266+
it('should support where filter for array type field', async () => {
267+
Post.dataSource.settings.allowExtendedOperators = true;
268+
const post = await Post.find({where: {and: [
269+
{
270+
categories: {'contains': ['AA']},
271+
},
272+
]}});
273+
should.exist(post);
274+
post.length.should.equal(1);
275+
});
266276
it('should support boolean types with false value', function(done) {
267277
Post.create(
268278
{title: 'T2', content: 'C2', approved: false, created: created},

0 commit comments

Comments
 (0)