Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support IN/NOT_IN/NOT_EQUAL operators #5198

Merged
merged 13 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Datastore/src/Query/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class Query implements QueryInterface
const OP_GREATER_THAN = 'GREATER_THAN';
const OP_GREATER_THAN_OR_EQUAL = 'GREATER_THAN_OR_EQUAL';
const OP_EQUALS = 'EQUAL';
const OP_NOT_EQUALS = 'NOT_EQUAL';
const OP_IN = 'IN';
const OP_NOT_IN = 'NOT_IN';
const OP_HAS_ANCESTOR = 'HAS_ANCESTOR';

const ORDER_DEFAULT = self::ORDER_ASCENDING;
Expand All @@ -99,6 +102,9 @@ class Query implements QueryInterface
self::OP_GREATER_THAN_OR_EQUAL,
self::OP_EQUALS,
self::OP_HAS_ANCESTOR,
self::OP_NOT_EQUALS,
self::OP_IN,
self::OP_NOT_IN,
];

/**
Expand All @@ -109,7 +115,10 @@ class Query implements QueryInterface
'<=' => self::OP_LESS_THAN_OR_EQUAL,
'>' => self::OP_GREATER_THAN,
'>=' => self::OP_GREATER_THAN_OR_EQUAL,
'=' => self::OP_EQUALS
'=' => self::OP_EQUALS,
'!=' => self::OP_NOT_EQUALS,
'IN' => self::OP_IN,
vishwarajanand marked this conversation as resolved.
Show resolved Hide resolved
'NOT_IN' => self::OP_NOT_IN,
];

/**
Expand Down
27 changes: 27 additions & 0 deletions Datastore/tests/Unit/Query/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,33 @@ public function testOperatorConstantsEquals()
$this->assertEquals('EQUAL', $filters[0]['propertyFilter']['op']);
}

public function testOperatorConstantsNotEquals()
{
$this->query->filter('propName', Query::OP_NOT_EQUALS, 'val');
$res = $this->query->queryObject();

$filters = $res['filter']['compositeFilter']['filters'];
$this->assertEquals('NOT_EQUAL', $filters[0]['propertyFilter']['op']);
}

public function testOperatorConstantsIn()
{
$this->query->filter('propName', Query::OP_IN, 'val');
$res = $this->query->queryObject();

$filters = $res['filter']['compositeFilter']['filters'];
$this->assertEquals('IN', $filters[0]['propertyFilter']['op']);
}

public function testOperatorConstantsNotIn()
{
$this->query->filter('propName', Query::OP_NOT_IN, 'val');
$res = $this->query->queryObject();

$filters = $res['filter']['compositeFilter']['filters'];
$this->assertEquals('NOT_IN', $filters[0]['propertyFilter']['op']);
}

public function testOperatorConstantsHasAncestor()
{
$this->query->filter('propName', Query::OP_HAS_ANCESTOR, 'val');
Expand Down