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 JSON queries #365

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
461 changes: 119 additions & 342 deletions src/Database/Query.php

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/Database/Validator/Queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function getDescription(): string
}

/**
* @param array<Query|string> $value
* @param array<Query|array<string, mixed>> $value
* @return bool
*/
public function isValid($value): bool
Expand Down Expand Up @@ -76,10 +76,10 @@ public function isValid($value): bool
Query::TYPE_SELECT => Base::METHOD_TYPE_SELECT,
Query::TYPE_LIMIT => Base::METHOD_TYPE_LIMIT,
Query::TYPE_OFFSET => Base::METHOD_TYPE_OFFSET,
Query::TYPE_CURSORAFTER,
Query::TYPE_CURSORBEFORE => Base::METHOD_TYPE_CURSOR,
Query::TYPE_ORDERASC,
Query::TYPE_ORDERDESC => Base::METHOD_TYPE_ORDER,
Query::TYPE_CURSOR_AFTER,
Query::TYPE_CURSOR_BEFORE => Base::METHOD_TYPE_CURSOR,
Query::TYPE_ORDER_ASC,
Query::TYPE_ORDER_DESC => Base::METHOD_TYPE_ORDER,
Query::TYPE_EQUAL,
Query::TYPE_NOT_EQUAL,
Query::TYPE_LESSER,
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Validator/Query/Cursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function isValid($value): bool

$method = $value->getMethod();

if ($method === Query::TYPE_CURSORAFTER || $method === Query::TYPE_CURSORBEFORE) {
if ($method === Query::TYPE_CURSOR_AFTER || $method === Query::TYPE_CURSOR_BEFORE) {
$cursor = $value->getValue();

if ($cursor instanceof Document) {
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Validator/Query/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function isValid($value): bool
$method = $value->getMethod();
$attribute = $value->getAttribute();

if ($method === Query::TYPE_ORDERASC || $method === Query::TYPE_ORDERDESC) {
if ($method === Query::TYPE_ORDER_ASC || $method === Query::TYPE_ORDER_DESC) {
if ($attribute === '') {
return true;
}
Expand Down
60 changes: 0 additions & 60 deletions tests/Database/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -12525,66 +12525,6 @@ public function testEmptyOperatorValues(): void
$this->assertEquals('Invalid query: Equal queries require at least one value.', $e->getMessage());
}

try {
static::getDatabase()->findOne('documents', [
Query::search('string', null),
]);
$this->fail('Failed to throw exception');
} catch (Exception $e) {
$this->assertInstanceOf(Exception::class, $e);
$this->assertEquals('Invalid query: Query type does not match expected: string', $e->getMessage());
}

try {
static::getDatabase()->findOne('documents', [
Query::notEqual('string', []),
]);
$this->fail('Failed to throw exception');
} catch (Exception $e) {
$this->assertInstanceOf(Exception::class, $e);
$this->assertEquals('Invalid query: Query type does not match expected: string', $e->getMessage());
}

try {
static::getDatabase()->findOne('documents', [
Query::lessThan('string', []),
]);
$this->fail('Failed to throw exception');
} catch (Exception $e) {
$this->assertInstanceOf(Exception::class, $e);
$this->assertEquals('Invalid query: Query type does not match expected: string', $e->getMessage());
}

try {
static::getDatabase()->findOne('documents', [
Query::lessThanEqual('string', []),
]);
$this->fail('Failed to throw exception');
} catch (Exception $e) {
$this->assertInstanceOf(Exception::class, $e);
$this->assertEquals('Invalid query: Query type does not match expected: string', $e->getMessage());
}

try {
static::getDatabase()->findOne('documents', [
Query::greaterThan('string', []),
]);
$this->fail('Failed to throw exception');
} catch (Exception $e) {
$this->assertInstanceOf(Exception::class, $e);
$this->assertEquals('Invalid query: Query type does not match expected: string', $e->getMessage());
}

try {
static::getDatabase()->findOne('documents', [
Query::greaterThanEqual('string', []),
]);
$this->fail('Failed to throw exception');
} catch (Exception $e) {
$this->assertInstanceOf(Exception::class, $e);
$this->assertEquals('Invalid query: Query type does not match expected: string', $e->getMessage());
}

try {
static::getDatabase()->findOne('documents', [
Query::contains('string', []),
Expand Down
Loading