From c29cc85602b9d3034c30081656999149907068cc Mon Sep 17 00:00:00 2001 From: Michael Vlach Date: Fri, 27 Sep 2024 19:41:17 +0200 Subject: [PATCH] [api] Add new search variant to PHP client api #1287 (#1288) * update tests * add search to query builder * fix coverage * change ts api client * Update main.ts * Update typescript.en-US.mdx * Update package-lock.json * linting errors * php api * lint * Update index.php * Update php.en-US.mdx * Update index.php * formatting * Update QueryBuilder.php * add more test queries * Update query.test.ts * Update index.php --- agdb/src/db/db_key_order.rs | 14 + agdb_api/php/ci.sh | 2 +- agdb_api/php/src/QueryBuilder.php | 283 ++++++++++++---- agdb_api/php/tests/QueryTest.php | 409 +++++++++++++++-------- agdb_api/typescript/tests/query.test.ts | 151 ++++++--- agdb_server/src/api.rs | 6 + agdb_server/test_queries.json | 167 +++++++++ agdb_web/pages/api-docs/php.en-US.mdx | 66 ++-- examples/server_client_php/src/index.php | 24 +- 9 files changed, 818 insertions(+), 304 deletions(-) diff --git a/agdb/src/db/db_key_order.rs b/agdb/src/db/db_key_order.rs index 1949ff4e..d5607e41 100644 --- a/agdb/src/db/db_key_order.rs +++ b/agdb/src/db/db_key_order.rs @@ -32,6 +32,18 @@ impl From<[DbKeyOrder; N]> for DbKeyOrders { } } +impl From for DbKeyOrders { + fn from(value: DbKeyOrder) -> Self { + Self(vec![value]) + } +} + +impl From<&DbKeyOrder> for DbKeyOrders { + fn from(value: &DbKeyOrder) -> Self { + Self(vec![value.clone()]) + } +} + #[cfg(test)] mod tests { use super::*; @@ -63,5 +75,7 @@ mod tests { let _orders = DbKeyOrders::from(vec![DbKeyOrder::Asc(1.into())]); let _orders = DbKeyOrders::from([DbKeyOrder::Asc(1.into())].as_slice()); let _orders = DbKeyOrders::from([DbKeyOrder::Asc(1.into())]); + let _orders = DbKeyOrders::from(DbKeyOrder::Asc(1.into())); + let _orders = DbKeyOrders::from(&DbKeyOrder::Asc(1.into())); } } diff --git a/agdb_api/php/ci.sh b/agdb_api/php/ci.sh index 2ff49c14..b61590b4 100755 --- a/agdb_api/php/ci.sh +++ b/agdb_api/php/ci.sh @@ -116,6 +116,6 @@ elif [[ "$1" == "openapi" ]]; then elif [[ "$1" == "test_queries" ]]; then test_queries else - echo "Usage: $0 [coverage|analysis|format|format:check|openapi|test_queries]" + echo "Usage: $0 [coverage|analyse|format|format:check|openapi|test_queries]" exit 1 fi diff --git a/agdb_api/php/src/QueryBuilder.php b/agdb_api/php/src/QueryBuilder.php index 797b7d1c..8705f43e 100644 --- a/agdb_api/php/src/QueryBuilder.php +++ b/agdb_api/php/src/QueryBuilder.php @@ -28,6 +28,68 @@ use Agnesoft\AgdbApi\Model\QueryConditionDataOneOf5KeyValue; use Agnesoft\AgdbApi\Model\DbKeyOrder; +class SearchQueryBuilder +{ + public QueryType|null $query; + public SearchQuery $search; + + public function __construct(QueryType|null $query) + { + $search = self::new_search(); + $this->query = $query; + + if ($query) { + // @phpstan-ignore-next-line if.alwaysTrue + if ($query->getInsertValues()) { + $query + ->getInsertValues() + ->setIds(new QueryIds(["search" => $search])); + // @phpstan-ignore-next-line if.alwaysTrue + } elseif ($query->getRemove()) { + $query->getRemove()->setSearch($search); + // @phpstan-ignore-next-line if.alwaysTrue + } elseif ($query->getRemoveValues()) { + $query + ->getRemoveValues() + ->setIds(new QueryIds(["search" => $search])); + // @phpstan-ignore-next-line if.alwaysTrue + } elseif ($query->getSelectAliases()) { + $query->getSelectAliases()->setSearch($search); + // @phpstan-ignore-next-line if.alwaysTrue + } elseif ($query->getSelectEdgeCount()) { + $query + ->getSelectEdgeCount() + ->setIds(new QueryIds(["search" => $search])); + // @phpstan-ignore-next-line if.alwaysTrue + } elseif ($query->getSelectKeys()) { + $query->getSelectKeys()->setSearch($search); + // @phpstan-ignore-next-line if.alwaysTrue + } elseif ($query->getSelectKeyCount()) { + $query->getSelectKeyCount()->setSearch($search); + } elseif ($query->getSelectValues()) { + $query + ->getSelectValues() + ->setIds(new QueryIds(["search" => $search])); + } + } + + $this->search = $search; + } + + private static function new_search(): SearchQuery + { + $query = new SearchQuery(); + $query->setAlgorithm(SearchQueryAlgorithm::BREADTH_FIRST); // @phpstan-ignore argument.type + $query->setOrigin(new QueryId(["id" => 0])); + $query->setDestination(new QueryId(["id" => 0])); + $query->setOffset(0); + $query->setLimit(0); + $query->setOrderBy([]); + $query->setConditions([]); + return $query; + } +} + class CountComparisonBuilder { public static function Equal(int $value): CountComparison @@ -628,6 +690,18 @@ public function ids( ]) ); } + + public function search(): SearchBuilder + { + return new SearchBuilder( + new QueryType([ + "insert_values" => new InsertValuesQuery([ + "values" => $this->data, + "ids" => new QueryIds(), + ]), + ]) + ); + } } class InsertBuilder @@ -771,6 +845,13 @@ public function query(): QueryType { return new QueryType(["remove_values" => $this->data]); } + + public function search(): SearchBuilder + { + return new SearchBuilder( + new QueryType(["remove_values" => $this->data]) + ); + } } class RemoveBuilder @@ -791,6 +872,11 @@ public function index(int|float|string|DbValue $value): RemoveIndexBuilder return new RemoveIndexBuilder(to_db_value($value)); } + public function search(): SearchBuilder + { + return new SearchBuilder(new QueryType(["remove" => new QueryIds()])); + } + public function values(array $data): RemoveValuesBuilder { return new RemoveValuesBuilder( @@ -801,47 +887,49 @@ public function values(array $data): RemoveValuesBuilder class SearchAlgorithmBuilder { - private SearchQuery $data; + private SearchQueryBuilder $data; - public function __construct(SearchQuery $data) + public function __construct(SearchQueryBuilder $data) { $this->data = $data; } public function from(string|int|QueryId $id): SearchFromBuilder { - $this->data->setOrigin(to_query_id($id)); + $this->data->search->setOrigin(to_query_id($id)); return new SearchFromBuilder($this->data); } public function to(string|int|QueryId $id): SearchToBuilder { - $this->data->setDestination(to_query_id($id)); + $this->data->search->setDestination(to_query_id($id)); return new SearchToBuilder($this->data); } } class SearchIndexValueBuilder { - private SearchQuery $data; + private SearchQueryBuilder $data; - public function __construct(SearchQuery $data) + public function __construct(SearchQueryBuilder $data) { $this->data = $data; } public function query(): QueryType { - return new QueryType(["search" => $this->data]); + return $this->data->query != null + ? $this->data->query + : new QueryType(["search" => $this->data->search]); } } class SearchIndexBuilder { - private SearchQuery $data; + private SearchQueryBuilder $data; private DbValue $key; - public function __construct(SearchQuery $data, DbValue $key) + public function __construct(SearchQueryBuilder $data, DbValue $key) { $this->data = $data; $this->key = $key; @@ -859,29 +947,29 @@ public function value( $kv->setValue(new Comparison(["equal" => to_db_value($v)])); $condition_data->setKeyValue($kv); $condition->setData($condition_data); - $this->data->setConditions([$condition]); + $this->data->search->setConditions([$condition]); return new SearchIndexValueBuilder($this->data); } } class SearchOrderByBuilder { - private SearchQuery $data; + private SearchQueryBuilder $data; - public function __construct(SearchQuery $data) + public function __construct(SearchQueryBuilder $data) { $this->data = $data; } public function limit(int $limit): SearchLimitBuilder { - $this->data->setLimit($limit); + $this->data->search->setLimit($limit); return new SearchLimitBuilder($this->data); } public function offset(int $offset): SearchOffsetBuilder { - $this->data->setOffset($offset); + $this->data->search->setOffset($offset); return new SearchOffsetBuilder($this->data); } @@ -892,7 +980,9 @@ public function where(): SearchWhereBuilder public function query(): QueryType { - return new QueryType(["search" => $this->data]); + return $this->data->query != null + ? $this->data->query + : new QueryType(["search" => $this->data->search]); } } @@ -950,19 +1040,22 @@ public function query(): QueryType { while ($this->data->__collapse_conditions()) { } - $this->data->__data->setConditions($this->data->__conditions[0]); - return new QueryType(["search" => $this->data->__data]); + $this->data->__data->search->setConditions( + $this->data->__conditions[0] + ); + return $this->data->__data->query ?: + new QueryType(["search" => $this->data->__data->search]); } } class SearchWhereBuilder { - public SearchQuery $__data; + public SearchQueryBuilder $__data; public string $__modifier = QueryConditionModifier::NONE; public string $__logic = QueryConditionLogic::_AND; public array $__conditions = [[]]; - public function __construct(SearchQuery $data) + public function __construct(SearchQueryBuilder $data) { $this->__data = $data; } @@ -1103,34 +1196,34 @@ public function __collapse_conditions(): bool class SearchFromBuilder { - private SearchQuery $data; + private SearchQueryBuilder $data; - public function __construct(SearchQuery $data) + public function __construct(SearchQueryBuilder $data) { $this->data = $data; } public function limit(int $limit): SearchLimitBuilder { - $this->data->setLimit($limit); + $this->data->search->setLimit($limit); return new SearchLimitBuilder($this->data); } public function offset(int $offset): SearchOffsetBuilder { - $this->data->setOffset($offset); + $this->data->search->setOffset($offset); return new SearchOffsetBuilder($this->data); } public function order_by(DbKeyOrder|array $data): SearchOrderByBuilder { - $this->data->setOrderBy(is_array($data) ? $data : [$data]); + $this->data->search->setOrderBy(is_array($data) ? $data : [$data]); return new SearchOrderByBuilder($this->data); } public function to(string|int|QueryId $id): SearchToBuilder { - $this->data->setDestination(to_query_id($id)); + $this->data->search->setDestination(to_query_id($id)); return new SearchToBuilder($this->data); } @@ -1141,15 +1234,17 @@ public function where(): SearchWhereBuilder public function query(): QueryType { - return new QueryType(["search" => $this->data]); + return $this->data->query != null + ? $this->data->query + : new QueryType(["search" => $this->data->search]); } } class SearchLimitBuilder { - private SearchQuery $data; + private SearchQueryBuilder $data; - public function __construct(SearchQuery $data) + public function __construct(SearchQueryBuilder $data) { $this->data = $data; } @@ -1161,22 +1256,24 @@ public function where(): SearchWhereBuilder public function query(): QueryType { - return new QueryType(["search" => $this->data]); + return $this->data->query != null + ? $this->data->query + : new QueryType(["search" => $this->data->search]); } } class SearchOffsetBuilder { - private SearchQuery $data; + private SearchQueryBuilder $data; - public function __construct(SearchQuery $data) + public function __construct(SearchQueryBuilder $data) { $this->data = $data; } public function limit(int $limit): SearchLimitBuilder { - $this->data->setLimit($limit); + $this->data->search->setLimit($limit); return new SearchLimitBuilder($this->data); } @@ -1187,34 +1284,36 @@ public function where(): SearchWhereBuilder public function query(): QueryType { - return new QueryType(["search" => $this->data]); + return $this->data->query != null + ? $this->data->query + : new QueryType(["search" => $this->data->search]); } } class SearchToBuilder { - private SearchQuery $data; + private SearchQueryBuilder $data; - public function __construct(SearchQuery $data) + public function __construct(SearchQueryBuilder $data) { $this->data = $data; } public function limit(int $limit): SearchLimitBuilder { - $this->data->setLimit($limit); + $this->data->search->setLimit($limit); return new SearchLimitBuilder($this->data); } public function offset(int $offset): SearchOffsetBuilder { - $this->data->setOffset($offset); + $this->data->search->setOffset($offset); return new SearchOffsetBuilder($this->data); } public function order_by(DbKeyOrder|array $data): SearchOrderByBuilder { - $this->data->setOrderBy(is_array($data) ? $data : [$data]); + $this->data->search->setOrderBy(is_array($data) ? $data : [$data]); return new SearchOrderByBuilder($this->data); } @@ -1225,65 +1324,56 @@ public function where(): SearchWhereBuilder public function query(): QueryType { - return new QueryType(["search" => $this->data]); + return $this->data->query != null + ? $this->data->query + : new QueryType(["search" => $this->data->search]); } } class SearchBuilder { + private SearchQueryBuilder $data; + + public function __construct(QueryType|null $query) + { + $this->data = new SearchQueryBuilder($query); + } + public function breadth_first(): SearchAlgorithmBuilder { - $search = self::new_search(); - return new SearchAlgorithmBuilder($search); + $this->data->search->setAlgorithm(SearchQueryAlgorithm::BREADTH_FIRST); // @phpstan-ignore argument.type + return new SearchAlgorithmBuilder($this->data); } public function depth_first(): SearchAlgorithmBuilder { - $search = self::new_search(); - $search->setAlgorithm(SearchQueryAlgorithm::DEPTH_FIRST); // @phpstan-ignore argument.type - return new SearchAlgorithmBuilder($search); + $this->data->search->setAlgorithm(SearchQueryAlgorithm::DEPTH_FIRST); // @phpstan-ignore argument.type + return new SearchAlgorithmBuilder($this->data); } public function elements(): SearchToBuilder { - $search = self::new_search(); - $search->setAlgorithm(SearchQueryAlgorithm::ELEMENTS); // @phpstan-ignore argument.type - return new SearchToBuilder($search); + $this->data->search->setAlgorithm(SearchQueryAlgorithm::ELEMENTS); // @phpstan-ignore argument.type + return new SearchToBuilder($this->data); } public function from(string|int|QueryId $id): SearchFromBuilder { - $search = self::new_search(); - $search->setOrigin(to_query_id($id)); - return new SearchFromBuilder($search); + $this->data->search->setOrigin(to_query_id($id)); + return new SearchFromBuilder($this->data); } public function index( int|float|string|array|DbValue $key ): SearchIndexBuilder { - $search = self::new_search(); - $search->setAlgorithm(SearchQueryAlgorithm::INDEX); // @phpstan-ignore argument.type - return new SearchIndexBuilder($search, to_db_value($key)); + $this->data->search->setAlgorithm(SearchQueryAlgorithm::INDEX); // @phpstan-ignore argument.type + return new SearchIndexBuilder($this->data, to_db_value($key)); } public function to(string|int|QueryId $id): SearchToBuilder { - $search = self::new_search(); - $search->setDestination(to_query_id($id)); - return new SearchToBuilder($search); - } - - private static function new_search(): SearchQuery - { - $query = new SearchQuery(); - $query->setAlgorithm(SearchQueryAlgorithm::BREADTH_FIRST); // @phpstan-ignore argument.type - $query->setOrigin(new QueryId(["id" => 0])); - $query->setDestination(new QueryId(["id" => 0])); - $query->setOffset(0); - $query->setLimit(0); - $query->setOrderBy([]); - $query->setConditions([]); - return $query; + $this->data->search->setDestination(to_query_id($id)); + return new SearchToBuilder($this->data); } } @@ -1314,6 +1404,13 @@ public function query(): QueryType { return new QueryType(["select_all_aliases" => new stdClass()]); } + + public function search(): SearchBuilder + { + return new SearchBuilder( + new QueryType(["select_aliases" => new QueryIds()]) + ); + } } class SelectEdgeCountIdsBuilder @@ -1353,6 +1450,19 @@ public function ids( ]) ); } + + public function search(): SearchBuilder + { + return new SearchBuilder( + new QueryType([ + "select_edge_count" => new SelectEdgeCountQuery([ + "from" => $this->from, + "to" => $this->to, + "ids" => new QueryIds(), + ]), + ]) + ); + } } class SelectValuesIdsBuilder @@ -1385,6 +1495,13 @@ public function ids( $this->data->setIds(to_query_ids($ids)); return new SelectValuesIdsBuilder($this->data); } + + public function search(): SearchBuilder + { + return new SearchBuilder( + new QueryType(["select_values" => $this->data]) + ); + } } class SelectIndexesBuilder @@ -1417,6 +1534,13 @@ public function ids( ): SelectKeysIdsBuilder { return new SelectKeysIdsBuilder(to_query_ids($ids)); } + + public function search(): SearchBuilder + { + return new SearchBuilder( + new QueryType(["select_keys" => new QueryIds()]) + ); + } } class SelectKeyCountIdsBuilder @@ -1441,6 +1565,13 @@ public function ids( ): SelectKeyCountIdsBuilder { return new SelectKeyCountIdsBuilder(to_query_ids($ids)); } + + public function search(): SearchBuilder + { + return new SearchBuilder( + new QueryType(["select_key_count" => new QueryIds()]) + ); + } } class SelectNodeCountBuilder @@ -1501,6 +1632,18 @@ public function node_count(): SelectNodeCountBuilder return new SelectNodeCountBuilder(); } + public function search(): SearchBuilder + { + return new SearchBuilder( + new QueryType([ + "select_values" => new SelectValuesQuery([ + "keys" => [], + "ids" => new QueryIds(), + ]), + ]) + ); + } + public function values(array $data): SelectValuesBuilder { return new SelectValuesBuilder( @@ -1523,7 +1666,7 @@ public static function remove(): RemoveBuilder public static function search(): SearchBuilder { - return new SearchBuilder(); + return new SearchBuilder(null); } public static function select(): SelectBuilder diff --git a/agdb_api/php/tests/QueryTest.php b/agdb_api/php/tests/QueryTest.php index dc612d08..8a6cbb61 100644 --- a/agdb_api/php/tests/QueryTest.php +++ b/agdb_api/php/tests/QueryTest.php @@ -366,8 +366,9 @@ public function testQueryBuilder36(): void public function testQueryBuilder37(): void { $query = QueryBuilder::insert() - ->values_uniform(["k" => "v", 1 => 10]) - ->ids([1, 2]) + ->values([["k" => "v", 1 => 10], ["k" => 2]]) + ->search() + ->from("a") ->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[37][1], $json); @@ -376,114 +377,116 @@ public function testQueryBuilder38(): void { $query = QueryBuilder::insert() ->values_uniform(["k" => "v", 1 => 10]) - ->ids(QueryBuilder::search()->from("a")->query()) + ->ids([1, 2]) ->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[38][1], $json); } public function testQueryBuilder39(): void { - $query = QueryBuilder::remove()->aliases("a")->query(); + $query = QueryBuilder::insert() + ->values_uniform(["k" => "v", 1 => 10]) + ->ids(QueryBuilder::search()->from("a")->query()) + ->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[39][1], $json); } public function testQueryBuilder40(): void { - $query = QueryBuilder::remove() - ->aliases(["a", "b"]) + $query = QueryBuilder::insert() + ->values_uniform(["k" => "v", 1 => 10]) + ->search() + ->from("a") ->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[40][1], $json); } public function testQueryBuilder41(): void { - $query = QueryBuilder::remove()->ids(1)->query(); + $query = QueryBuilder::remove()->aliases("a")->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[41][1], $json); } public function testQueryBuilder42(): void { - $query = QueryBuilder::remove()->ids("a")->query(); + $query = QueryBuilder::remove() + ->aliases(["a", "b"]) + ->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[42][1], $json); } public function testQueryBuilder43(): void { - $query = QueryBuilder::remove() - ->ids([1, 2]) - ->query(); + $query = QueryBuilder::remove()->ids(1)->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[43][1], $json); } public function testQueryBuilder44(): void { - $query = QueryBuilder::remove() - ->ids(["a", "b"]) - ->query(); + $query = QueryBuilder::remove()->ids("a")->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[44][1], $json); } public function testQueryBuilder45(): void { $query = QueryBuilder::remove() - ->ids(QueryBuilder::search()->from("a")->query()) + ->ids([1, 2]) ->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[45][1], $json); } public function testQueryBuilder46(): void { - $query = QueryBuilder::remove()->index("key")->query(); + $query = QueryBuilder::remove() + ->ids(["a", "b"]) + ->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[46][1], $json); } public function testQueryBuilder47(): void { $query = QueryBuilder::remove() - ->values(["k1", "k2"]) - ->ids([1, 2]) + ->ids(QueryBuilder::search()->from("a")->query()) ->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[47][1], $json); } public function testQueryBuilder48(): void { - $query = QueryBuilder::remove() - ->values(["k1", "k2"]) - ->ids(QueryBuilder::search()->from("a")->query()) - ->query(); + $query = QueryBuilder::remove()->search()->from("a")->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[48][1], $json); } public function testQueryBuilder49(): void { - $query = QueryBuilder::select() - ->aliases() - ->ids([1, 2]) - ->query(); + $query = QueryBuilder::remove()->index("key")->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[49][1], $json); } public function testQueryBuilder50(): void { - $query = QueryBuilder::select() - ->aliases() - ->ids(QueryBuilder::search()->from(1)->query()) + $query = QueryBuilder::remove() + ->values(["k1", "k2"]) + ->ids([1, 2]) ->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[50][1], $json); } public function testQueryBuilder51(): void { - $query = QueryBuilder::select()->aliases()->query(); + $query = QueryBuilder::remove() + ->values(["k1", "k2"]) + ->ids(QueryBuilder::search()->from("a")->query()) + ->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[51][1], $json); } public function testQueryBuilder52(): void { - $query = QueryBuilder::select() - ->edge_count() - ->ids([1, 2]) + $query = QueryBuilder::remove() + ->values(["k1", "k2"]) + ->search() + ->from("a") ->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[52][1], $json); @@ -491,7 +494,7 @@ public function testQueryBuilder52(): void public function testQueryBuilder53(): void { $query = QueryBuilder::select() - ->edge_count_from() + ->aliases() ->ids([1, 2]) ->query(); $json = $query->jsonSerialize(); @@ -500,99 +503,101 @@ public function testQueryBuilder53(): void public function testQueryBuilder54(): void { $query = QueryBuilder::select() - ->edge_count_to() - ->ids([1, 2]) + ->aliases() + ->ids(QueryBuilder::search()->from(1)->query()) ->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[54][1], $json); } public function testQueryBuilder55(): void { - $query = QueryBuilder::select()->ids("a")->query(); + $query = QueryBuilder::select()->aliases()->search()->from(1)->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[55][1], $json); } public function testQueryBuilder56(): void { - $query = QueryBuilder::select() - ->ids([1, 2]) - ->query(); + $query = QueryBuilder::select()->aliases()->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[56][1], $json); } public function testQueryBuilder57(): void { $query = QueryBuilder::select() - ->ids(QueryBuilder::search()->from(1)->query()) + ->edge_count() + ->ids([1, 2]) ->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[57][1], $json); } public function testQueryBuilder58(): void { - $query = QueryBuilder::select()->indexes()->query(); + $query = QueryBuilder::select() + ->edge_count_from() + ->ids([1, 2]) + ->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[58][1], $json); } public function testQueryBuilder59(): void { - $query = QueryBuilder::select()->keys()->ids("a")->query(); + $query = QueryBuilder::select() + ->edge_count_to() + ->ids([1, 2]) + ->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[59][1], $json); } public function testQueryBuilder60(): void { $query = QueryBuilder::select() - ->keys() - ->ids([1, 2]) + ->edge_count() + ->search() + ->from(1) ->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[60][1], $json); } public function testQueryBuilder61(): void { - $query = QueryBuilder::select() - ->keys() - ->ids(QueryBuilder::search()->from(1)->query()) - ->query(); + $query = QueryBuilder::select()->ids("a")->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[61][1], $json); } public function testQueryBuilder62(): void { - $query = QueryBuilder::select()->key_count()->ids("a")->query(); + $query = QueryBuilder::select() + ->ids([1, 2]) + ->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[62][1], $json); } public function testQueryBuilder63(): void { $query = QueryBuilder::select() - ->key_count() - ->ids([1, 2]) + ->ids(QueryBuilder::search()->from(1)->query()) ->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[63][1], $json); } public function testQueryBuilder64(): void { - $query = QueryBuilder::select() - ->key_count() - ->ids(QueryBuilder::search()->from(1)->query()) - ->query(); + $query = QueryBuilder::select()->search()->from(1)->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[64][1], $json); } public function testQueryBuilder65(): void { - $query = QueryBuilder::select()->node_count()->query(); + $query = QueryBuilder::select()->search()->to(1)->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[65][1], $json); } public function testQueryBuilder66(): void { $query = QueryBuilder::select() - ->values(["k", "k2"]) - ->ids("a") + ->search() + ->index("age") + ->value(20) ->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[66][1], $json); @@ -600,8 +605,9 @@ public function testQueryBuilder66(): void public function testQueryBuilder67(): void { $query = QueryBuilder::select() - ->values(["k", "k2"]) - ->ids([1, 2]) + ->search() + ->from("a") + ->limit(10) ->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[67][1], $json); @@ -609,61 +615,196 @@ public function testQueryBuilder67(): void public function testQueryBuilder68(): void { $query = QueryBuilder::select() - ->values(["k", "k2"]) - ->ids(QueryBuilder::search()->from(1)->query()) + ->search() + ->from("a") + ->offset(10) ->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[68][1], $json); } public function testQueryBuilder69(): void { - $query = QueryBuilder::search()->from("a")->query(); + $query = QueryBuilder::select() + ->search() + ->from("a") + ->order_by(DbKeyOrderBuilder::Desc("age")) + ->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[69][1], $json); } public function testQueryBuilder70(): void { - $query = QueryBuilder::search()->to(1)->query(); + $query = QueryBuilder::select() + ->search() + ->from("a") + ->where() + ->node() + ->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[70][1], $json); } public function testQueryBuilder71(): void { - $query = QueryBuilder::search()->from("a")->to("b")->query(); + $query = QueryBuilder::select()->indexes()->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[71][1], $json); } public function testQueryBuilder72(): void { - $query = QueryBuilder::search()->breadth_first()->from("a")->query(); + $query = QueryBuilder::select()->keys()->ids("a")->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[72][1], $json); } public function testQueryBuilder73(): void { - $query = QueryBuilder::search()->depth_first()->to(1)->query(); + $query = QueryBuilder::select() + ->keys() + ->ids([1, 2]) + ->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[73][1], $json); } public function testQueryBuilder74(): void { - $query = QueryBuilder::search()->depth_first()->from("a")->query(); + $query = QueryBuilder::select() + ->keys() + ->ids(QueryBuilder::search()->from(1)->query()) + ->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[74][1], $json); } public function testQueryBuilder75(): void { - $query = QueryBuilder::search()->elements()->query(); + $query = QueryBuilder::select()->keys()->search()->from(1)->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[75][1], $json); } public function testQueryBuilder76(): void { - $query = QueryBuilder::search()->index("age")->value(20)->query(); + $query = QueryBuilder::select()->key_count()->ids("a")->query(); $json = $query->jsonSerialize(); $this->assertEquals(self::$test_queries[76][1], $json); } public function testQueryBuilder77(): void + { + $query = QueryBuilder::select() + ->key_count() + ->ids([1, 2]) + ->query(); + $json = $query->jsonSerialize(); + $this->assertEquals(self::$test_queries[77][1], $json); + } + public function testQueryBuilder78(): void + { + $query = QueryBuilder::select() + ->key_count() + ->ids(QueryBuilder::search()->from(1)->query()) + ->query(); + $json = $query->jsonSerialize(); + $this->assertEquals(self::$test_queries[78][1], $json); + } + public function testQueryBuilder79(): void + { + $query = QueryBuilder::select() + ->key_count() + ->search() + ->from(1) + ->query(); + $json = $query->jsonSerialize(); + $this->assertEquals(self::$test_queries[79][1], $json); + } + public function testQueryBuilder80(): void + { + $query = QueryBuilder::select()->node_count()->query(); + $json = $query->jsonSerialize(); + $this->assertEquals(self::$test_queries[80][1], $json); + } + public function testQueryBuilder81(): void + { + $query = QueryBuilder::select() + ->values(["k", "k2"]) + ->ids("a") + ->query(); + $json = $query->jsonSerialize(); + $this->assertEquals(self::$test_queries[81][1], $json); + } + public function testQueryBuilder82(): void + { + $query = QueryBuilder::select() + ->values(["k", "k2"]) + ->ids([1, 2]) + ->query(); + $json = $query->jsonSerialize(); + $this->assertEquals(self::$test_queries[82][1], $json); + } + public function testQueryBuilder83(): void + { + $query = QueryBuilder::select() + ->values(["k", "k2"]) + ->ids(QueryBuilder::search()->from(1)->query()) + ->query(); + $json = $query->jsonSerialize(); + $this->assertEquals(self::$test_queries[83][1], $json); + } + public function testQueryBuilder84(): void + { + $query = QueryBuilder::select() + ->values(["k", "k2"]) + ->search() + ->from(1) + ->query(); + $json = $query->jsonSerialize(); + $this->assertEquals(self::$test_queries[84][1], $json); + } + public function testQueryBuilder85(): void + { + $query = QueryBuilder::search()->from("a")->query(); + $json = $query->jsonSerialize(); + $this->assertEquals(self::$test_queries[85][1], $json); + } + public function testQueryBuilder86(): void + { + $query = QueryBuilder::search()->to(1)->query(); + $json = $query->jsonSerialize(); + $this->assertEquals(self::$test_queries[86][1], $json); + } + public function testQueryBuilder87(): void + { + $query = QueryBuilder::search()->from("a")->to("b")->query(); + $json = $query->jsonSerialize(); + $this->assertEquals(self::$test_queries[87][1], $json); + } + public function testQueryBuilder88(): void + { + $query = QueryBuilder::search()->breadth_first()->from("a")->query(); + $json = $query->jsonSerialize(); + $this->assertEquals(self::$test_queries[88][1], $json); + } + public function testQueryBuilder89(): void + { + $query = QueryBuilder::search()->depth_first()->to(1)->query(); + $json = $query->jsonSerialize(); + $this->assertEquals(self::$test_queries[89][1], $json); + } + public function testQueryBuilder90(): void + { + $query = QueryBuilder::search()->depth_first()->from("a")->query(); + $json = $query->jsonSerialize(); + $this->assertEquals(self::$test_queries[90][1], $json); + } + public function testQueryBuilder91(): void + { + $query = QueryBuilder::search()->elements()->query(); + $json = $query->jsonSerialize(); + $this->assertEquals(self::$test_queries[91][1], $json); + } + public function testQueryBuilder92(): void + { + $query = QueryBuilder::search()->index("age")->value(20)->query(); + $json = $query->jsonSerialize(); + $this->assertEquals(self::$test_queries[92][1], $json); + } + public function testQueryBuilder93(): void { $query = QueryBuilder::search() ->from(1) @@ -673,21 +814,21 @@ public function testQueryBuilder77(): void ]) ->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[77][1], $json); + $this->assertEquals(self::$test_queries[93][1], $json); } - public function testQueryBuilder78(): void + public function testQueryBuilder94(): void { $query = QueryBuilder::search()->from(1)->offset(10)->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[78][1], $json); + $this->assertEquals(self::$test_queries[94][1], $json); } - public function testQueryBuilder79(): void + public function testQueryBuilder95(): void { $query = QueryBuilder::search()->from(1)->limit(5)->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[79][1], $json); + $this->assertEquals(self::$test_queries[95][1], $json); } - public function testQueryBuilder80(): void + public function testQueryBuilder96(): void { $query = QueryBuilder::search() ->from(1) @@ -695,9 +836,9 @@ public function testQueryBuilder80(): void ->offset(10) ->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[80][1], $json); + $this->assertEquals(self::$test_queries[96][1], $json); } - public function testQueryBuilder81(): void + public function testQueryBuilder97(): void { $query = QueryBuilder::search() ->from(1) @@ -705,9 +846,9 @@ public function testQueryBuilder81(): void ->limit(5) ->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[81][1], $json); + $this->assertEquals(self::$test_queries[97][1], $json); } - public function testQueryBuilder82(): void + public function testQueryBuilder98(): void { $query = QueryBuilder::search() ->from(1) @@ -716,15 +857,15 @@ public function testQueryBuilder82(): void ->limit(5) ->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[82][1], $json); + $this->assertEquals(self::$test_queries[98][1], $json); } - public function testQueryBuilder83(): void + public function testQueryBuilder99(): void { $query = QueryBuilder::search()->from(1)->offset(10)->limit(5)->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[83][1], $json); + $this->assertEquals(self::$test_queries[99][1], $json); } - public function testQueryBuilder84(): void + public function testQueryBuilder100(): void { $query = QueryBuilder::search() ->from(1) @@ -732,15 +873,15 @@ public function testQueryBuilder84(): void ->distance(CountComparisonBuilder::LessThan(3)) ->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[84][1], $json); + $this->assertEquals(self::$test_queries[100][1], $json); } - public function testQueryBuilder85(): void + public function testQueryBuilder101(): void { $query = QueryBuilder::search()->from(1)->where()->edge()->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[85][1], $json); + $this->assertEquals(self::$test_queries[101][1], $json); } - public function testQueryBuilder86(): void + public function testQueryBuilder102(): void { $query = QueryBuilder::search() ->from(1) @@ -748,9 +889,9 @@ public function testQueryBuilder86(): void ->edge_count(CountComparisonBuilder::GreaterThan(2)) ->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[86][1], $json); + $this->assertEquals(self::$test_queries[102][1], $json); } - public function testQueryBuilder87(): void + public function testQueryBuilder103(): void { $query = QueryBuilder::search() ->from(1) @@ -758,9 +899,9 @@ public function testQueryBuilder87(): void ->edge_count_from(CountComparisonBuilder::Equal(1)) ->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[87][1], $json); + $this->assertEquals(self::$test_queries[103][1], $json); } - public function testQueryBuilder88(): void + public function testQueryBuilder104(): void { $query = QueryBuilder::search() ->from(1) @@ -768,15 +909,15 @@ public function testQueryBuilder88(): void ->edge_count_to(CountComparisonBuilder::NotEqual(1)) ->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[88][1], $json); + $this->assertEquals(self::$test_queries[104][1], $json); } - public function testQueryBuilder89(): void + public function testQueryBuilder105(): void { $query = QueryBuilder::search()->from(1)->where()->node()->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[89][1], $json); + $this->assertEquals(self::$test_queries[105][1], $json); } - public function testQueryBuilder90(): void + public function testQueryBuilder106(): void { $query = QueryBuilder::search() ->from(1) @@ -785,9 +926,9 @@ public function testQueryBuilder90(): void ->value(ComparisonBuilder::Equal(1)) ->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[90][1], $json); + $this->assertEquals(self::$test_queries[106][1], $json); } - public function testQueryBuilder91(): void + public function testQueryBuilder107(): void { $query = QueryBuilder::search() ->from(1) @@ -795,9 +936,9 @@ public function testQueryBuilder91(): void ->keys(["k1", "k2"]) ->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[91][1], $json); + $this->assertEquals(self::$test_queries[107][1], $json); } - public function testQueryBuilder92(): void + public function testQueryBuilder108(): void { $query = QueryBuilder::search() ->from(1) @@ -806,9 +947,9 @@ public function testQueryBuilder92(): void ->keys(["k1", "k2"]) ->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[92][1], $json); + $this->assertEquals(self::$test_queries[108][1], $json); } - public function testQueryBuilder93(): void + public function testQueryBuilder109(): void { $query = QueryBuilder::search() ->from(1) @@ -816,9 +957,9 @@ public function testQueryBuilder93(): void ->ids([1, 2]) ->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[93][1], $json); + $this->assertEquals(self::$test_queries[109][1], $json); } - public function testQueryBuilder94(): void + public function testQueryBuilder110(): void { $query = QueryBuilder::search() ->from(1) @@ -827,9 +968,9 @@ public function testQueryBuilder94(): void ->keys(["k"]) ->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[94][1], $json); + $this->assertEquals(self::$test_queries[110][1], $json); } - public function testQueryBuilder95(): void + public function testQueryBuilder111(): void { $query = QueryBuilder::search() ->from(1) @@ -838,9 +979,9 @@ public function testQueryBuilder95(): void ->ids([1, 2]) ->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[95][1], $json); + $this->assertEquals(self::$test_queries[111][1], $json); } - public function testQueryBuilder96(): void + public function testQueryBuilder112(): void { $query = QueryBuilder::search() ->from(1) @@ -849,9 +990,9 @@ public function testQueryBuilder96(): void ->ids("a") ->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[96][1], $json); + $this->assertEquals(self::$test_queries[112][1], $json); } - public function testQueryBuilder97(): void + public function testQueryBuilder113(): void { $query = QueryBuilder::search() ->from(1) @@ -861,9 +1002,9 @@ public function testQueryBuilder97(): void ->edge() ->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[97][1], $json); + $this->assertEquals(self::$test_queries[113][1], $json); } - public function testQueryBuilder98(): void + public function testQueryBuilder114(): void { $query = QueryBuilder::search() ->from(1) @@ -873,9 +1014,9 @@ public function testQueryBuilder98(): void ->distance(CountComparisonBuilder::GreaterThanOrEqual(3)) ->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[98][1], $json); + $this->assertEquals(self::$test_queries[114][1], $json); } - public function testQueryBuilder99(): void + public function testQueryBuilder115(): void { $query = QueryBuilder::search() ->from(1) @@ -890,9 +1031,9 @@ public function testQueryBuilder99(): void ->end_where() ->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[99][1], $json); + $this->assertEquals(self::$test_queries[115][1], $json); } - public function testQueryBuilder100(): void + public function testQueryBuilder116(): void { $query = QueryBuilder::search() ->from(1) @@ -907,9 +1048,9 @@ public function testQueryBuilder100(): void ->end_where() ->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[100][1], $json); + $this->assertEquals(self::$test_queries[116][1], $json); } - public function testQueryBuilder101(): void + public function testQueryBuilder117(): void { $query = QueryBuilder::search() ->from(1) @@ -924,9 +1065,9 @@ public function testQueryBuilder101(): void ->end_where() ->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[101][1], $json); + $this->assertEquals(self::$test_queries[117][1], $json); } - public function testQueryBuilder102(): void + public function testQueryBuilder118(): void { $query = QueryBuilder::search() ->from(1) @@ -935,9 +1076,9 @@ public function testQueryBuilder102(): void ->node() ->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[102][1], $json); + $this->assertEquals(self::$test_queries[118][1], $json); } - public function testQueryBuilder103(): void + public function testQueryBuilder119(): void { $query = QueryBuilder::search() ->from(1) @@ -946,9 +1087,9 @@ public function testQueryBuilder103(): void ->node() ->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[103][1], $json); + $this->assertEquals(self::$test_queries[119][1], $json); } - public function testQueryBuilder104(): void + public function testQueryBuilder120(): void { $query = QueryBuilder::search() ->from(1) @@ -957,27 +1098,27 @@ public function testQueryBuilder104(): void ->node() ->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[104][1], $json); + $this->assertEquals(self::$test_queries[120][1], $json); } - public function testQueryBuilder105(): void + public function testQueryBuilder121(): void { $query = QueryBuilder::search()->to(1)->offset(1)->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[105][1], $json); + $this->assertEquals(self::$test_queries[121][1], $json); } - public function testQueryBuilder106(): void + public function testQueryBuilder122(): void { $query = QueryBuilder::search()->to(1)->limit(1)->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[106][1], $json); + $this->assertEquals(self::$test_queries[122][1], $json); } - public function testQueryBuilder107(): void + public function testQueryBuilder123(): void { $query = QueryBuilder::search()->to(1)->where()->node()->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[107][1], $json); + $this->assertEquals(self::$test_queries[123][1], $json); } - public function testQueryBuilder108(): void + public function testQueryBuilder124(): void { $query = QueryBuilder::search() ->to(1) @@ -986,7 +1127,7 @@ public function testQueryBuilder108(): void ->node() ->query(); $json = $query->jsonSerialize(); - $this->assertEquals(self::$test_queries[108][1], $json); + $this->assertEquals(self::$test_queries[124][1], $json); } } diff --git a/agdb_api/typescript/tests/query.test.ts b/agdb_api/typescript/tests/query.test.ts index 0aee7789..cad384cf 100644 --- a/agdb_api/typescript/tests/query.test.ts +++ b/agdb_api/typescript/tests/query.test.ts @@ -514,19 +514,62 @@ describe("query tests", () => { expect(query).toEqual(test_queries[64][1]); }); + it(`QueryBuilder::select().search().to(1).query()`, () => { + let query = QueryBuilder.select().search().to(1).query(); + expect(query).toEqual(test_queries[65][1]); + }); + + it(`QueryBuilder::select().search().index("age").value(20).query()`, () => { + let query = QueryBuilder.select() + .search() + .index("age") + .value(20) + .query(); + expect(query).toEqual(test_queries[66][1]); + }); + + it(`QueryBuilder::select().search().from("a").limit(10).query()`, () => { + let query = QueryBuilder.select().search().from("a").limit(10).query(); + expect(query).toEqual(test_queries[67][1]); + }); + + it(`QueryBuilder::select().search().from("a").offset(10).query()`, () => { + let query = QueryBuilder.select().search().from("a").offset(10).query(); + expect(query).toEqual(test_queries[68][1]); + }); + + it(`QueryBuilder::select().search().from("a").order_by(DbKeyOrder::Desc("age".into())).query()`, () => { + let query = QueryBuilder.select() + .search() + .from("a") + .order_by(DbKeyOrder.Desc("age")) + .query(); + expect(query).toEqual(test_queries[69][1]); + }); + + it(`QueryBuilder::select().search().from("a").where_().node().query()`, () => { + let query = QueryBuilder.select() + .search() + .from("a") + .where() + .node() + .query(); + expect(query).toEqual(test_queries[70][1]); + }); + it(`QueryBuilder::select().indexes().query()`, () => { let query = QueryBuilder.select().indexes().query(); - expect(query).toEqual(test_queries[65][1]); + expect(query).toEqual(test_queries[71][1]); }); it(`QueryBuilder::select().keys().ids("a").query()`, () => { let query = QueryBuilder.select().keys().ids("a").query(); - expect(query).toEqual(test_queries[66][1]); + expect(query).toEqual(test_queries[72][1]); }); it(`QueryBuilder::select().keys().ids([1,2]).query()`, () => { let query = QueryBuilder.select().keys().ids([1, 2]).query(); - expect(query).toEqual(test_queries[67][1]); + expect(query).toEqual(test_queries[73][1]); }); it(`QueryBuilder::select().keys().ids(QueryBuilder::search().from(1).query()).query()`, () => { @@ -534,22 +577,22 @@ describe("query tests", () => { .keys() .ids(QueryBuilder.search().from(1).query()) .query(); - expect(query).toEqual(test_queries[68][1]); + expect(query).toEqual(test_queries[74][1]); }); it(`QueryBuilder::select().keys().search().from(1).query()`, () => { let query = QueryBuilder.select().keys().search().from(1).query(); - expect(query).toEqual(test_queries[69][1]); + expect(query).toEqual(test_queries[75][1]); }); it(`QueryBuilder::select().key_count().ids("a").query()`, () => { let query = QueryBuilder.select().key_count().ids("a").query(); - expect(query).toEqual(test_queries[70][1]); + expect(query).toEqual(test_queries[76][1]); }); it(`QueryBuilder::select().key_count().ids([1,2]).query()`, () => { let query = QueryBuilder.select().key_count().ids([1, 2]).query(); - expect(query).toEqual(test_queries[71][1]); + expect(query).toEqual(test_queries[77][1]); }); it(`QueryBuilder::select().key_count().ids(QueryBuilder::search().from(1).query()).query()`, () => { @@ -557,22 +600,22 @@ describe("query tests", () => { .key_count() .ids(QueryBuilder.search().from(1).query()) .query(); - expect(query).toEqual(test_queries[72][1]); + expect(query).toEqual(test_queries[78][1]); }); it(`QueryBuilder::select().key_count().search().from(1).query()`, () => { let query = QueryBuilder.select().key_count().search().from(1).query(); - expect(query).toEqual(test_queries[73][1]); + expect(query).toEqual(test_queries[79][1]); }); it(`QueryBuilder::select().node_count().query()`, () => { let query = QueryBuilder.select().node_count().query(); - expect(query).toEqual(test_queries[74][1]); + expect(query).toEqual(test_queries[80][1]); }); it(`QueryBuilder::select().values(["k","k2"]).ids("a").query()`, () => { let query = QueryBuilder.select().values(["k", "k2"]).ids("a").query(); - expect(query).toEqual(test_queries[75][1]); + expect(query).toEqual(test_queries[81][1]); }); it(`QueryBuilder::select().values(["k","k2"]).ids([1,2]).query()`, () => { @@ -580,7 +623,7 @@ describe("query tests", () => { .values(["k", "k2"]) .ids([1, 2]) .query(); - expect(query).toEqual(test_queries[76][1]); + expect(query).toEqual(test_queries[82][1]); }); it(`QueryBuilder::select().values(["k","k2"]).ids(QueryBuilder::search().from(1).query()).query()`, () => { @@ -588,7 +631,7 @@ describe("query tests", () => { .values(["k", "k2"]) .ids(QueryBuilder.search().from(1).query()) .query(); - expect(query).toEqual(test_queries[77][1]); + expect(query).toEqual(test_queries[83][1]); }); it(`QueryBuilder::select().values(["k","k2"]).search().from(1).query()`, () => { @@ -597,47 +640,47 @@ describe("query tests", () => { .search() .from(1) .query(); - expect(query).toEqual(test_queries[78][1]); + expect(query).toEqual(test_queries[84][1]); }); it(`QueryBuilder::search().from("a").query()`, () => { let query = QueryBuilder.search().from("a").query(); - expect(query).toEqual(test_queries[79][1]); + expect(query).toEqual(test_queries[85][1]); }); it(`QueryBuilder::search().to(1).query()`, () => { let query = QueryBuilder.search().to(1).query(); - expect(query).toEqual(test_queries[80][1]); + expect(query).toEqual(test_queries[86][1]); }); it(`QueryBuilder::search().from("a").to("b").query()`, () => { let query = QueryBuilder.search().from("a").to("b").query(); - expect(query).toEqual(test_queries[81][1]); + expect(query).toEqual(test_queries[87][1]); }); it(`QueryBuilder::search().breadth_first().from("a").query()`, () => { let query = QueryBuilder.search().breadth_first().from("a").query(); - expect(query).toEqual(test_queries[82][1]); + expect(query).toEqual(test_queries[88][1]); }); it(`QueryBuilder::search().depth_first().to(1).query()`, () => { let query = QueryBuilder.search().depth_first().to(1).query(); - expect(query).toEqual(test_queries[83][1]); + expect(query).toEqual(test_queries[89][1]); }); it(`QueryBuilder::search().depth_first().from("a").query()`, () => { let query = QueryBuilder.search().depth_first().from("a").query(); - expect(query).toEqual(test_queries[84][1]); + expect(query).toEqual(test_queries[90][1]); }); it(`QueryBuilder::search().elements().query()`, () => { let query = QueryBuilder.search().elements().query(); - expect(query).toEqual(test_queries[85][1]); + expect(query).toEqual(test_queries[91][1]); }); it(`QueryBuilder::search().index("age").value(20).query()`, () => { let query = QueryBuilder.search().index("age").value(20).query(); - expect(query).toEqual(test_queries[86][1]); + expect(query).toEqual(test_queries[92][1]); }); it(`QueryBuilder::search().from(1).order_by([DbKeyOrder::Desc("age".into()),DbKeyOrder::Asc("name".into())]).query()`, () => { @@ -645,17 +688,17 @@ describe("query tests", () => { .from(1) .order_by([DbKeyOrder.Desc("age"), DbKeyOrder.Asc("name")]) .query(); - expect(query).toEqual(test_queries[87][1]); + expect(query).toEqual(test_queries[93][1]); }); it(`QueryBuilder::search().from(1).offset(10).query()`, () => { let query = QueryBuilder.search().from(1).offset(10).query(); - expect(query).toEqual(test_queries[88][1]); + expect(query).toEqual(test_queries[94][1]); }); it(`QueryBuilder::search().from(1).limit(5).query()`, () => { let query = QueryBuilder.search().from(1).limit(5).query(); - expect(query).toEqual(test_queries[89][1]); + expect(query).toEqual(test_queries[95][1]); }); it(`QueryBuilder::search().from(1).order_by([DbKeyOrder::Desc("k".into())]).offset(10).query()`, () => { @@ -664,7 +707,7 @@ describe("query tests", () => { .order_by([DbKeyOrder.Desc("k")]) .offset(10) .query(); - expect(query).toEqual(test_queries[90][1]); + expect(query).toEqual(test_queries[96][1]); }); it(`QueryBuilder::search().from(1).order_by([DbKeyOrder::Desc("k".into())]).limit(5).query()`, () => { @@ -673,7 +716,7 @@ describe("query tests", () => { .order_by([DbKeyOrder.Desc("k")]) .limit(5) .query(); - expect(query).toEqual(test_queries[91][1]); + expect(query).toEqual(test_queries[97][1]); }); it(`QueryBuilder::search().from(1).order_by([DbKeyOrder::Desc("k".into())]).offset(10).limit(5).query()`, () => { @@ -683,12 +726,12 @@ describe("query tests", () => { .offset(10) .limit(5) .query(); - expect(query).toEqual(test_queries[92][1]); + expect(query).toEqual(test_queries[98][1]); }); it(`QueryBuilder::search().from(1).offset(10).limit(5).query()`, () => { let query = QueryBuilder.search().from(1).offset(10).limit(5).query(); - expect(query).toEqual(test_queries[93][1]); + expect(query).toEqual(test_queries[99][1]); }); it(`QueryBuilder::search().from(1).where_().distance(CountComparison::LessThan(3)).query()`, () => { @@ -697,12 +740,12 @@ describe("query tests", () => { .where() .distance(CountComparison.LessThan(3)) .query(); - expect(query).toEqual(test_queries[94][1]); + expect(query).toEqual(test_queries[100][1]); }); it(`QueryBuilder::search().from(1).where_().edge().query()`, () => { let query = QueryBuilder.search().from(1).where().edge().query(); - expect(query).toEqual(test_queries[95][1]); + expect(query).toEqual(test_queries[101][1]); }); it(`QueryBuilder::search().from(1).where_().edge_count(CountComparison::GreaterThan(2)).query()`, () => { @@ -711,7 +754,7 @@ describe("query tests", () => { .where() .edge_count(CountComparison.GreaterThan(2)) .query(); - expect(query).toEqual(test_queries[96][1]); + expect(query).toEqual(test_queries[102][1]); }); it(`QueryBuilder::search().from(1).where_().edge_count_from(CountComparison::Equal(1)).query()`, () => { @@ -720,7 +763,7 @@ describe("query tests", () => { .where() .edge_count_from(CountComparison.Equal(1)) .query(); - expect(query).toEqual(test_queries[97][1]); + expect(query).toEqual(test_queries[103][1]); }); it(`QueryBuilder::search().from(1).where_().edge_count_to(CountComparison::NotEqual(1)).query()`, () => { @@ -729,12 +772,12 @@ describe("query tests", () => { .where() .edge_count_to(CountComparison.NotEqual(1)) .query(); - expect(query).toEqual(test_queries[98][1]); + expect(query).toEqual(test_queries[104][1]); }); it(`QueryBuilder::search().from(1).where_().node().query()`, () => { let query = QueryBuilder.search().from(1).where().node().query(); - expect(query).toEqual(test_queries[99][1]); + expect(query).toEqual(test_queries[105][1]); }); it(`QueryBuilder::search().from(1).where_().key("k").value(Comparison::Equal(1.into())).query()`, () => { @@ -744,7 +787,7 @@ describe("query tests", () => { .key("k") .value(Comparison.Equal(1)) .query(); - expect(query).toEqual(test_queries[100][1]); + expect(query).toEqual(test_queries[106][1]); }); it(`QueryBuilder::search().from(1).where_().keys(["k1","k2"]).query()`, () => { @@ -753,7 +796,7 @@ describe("query tests", () => { .where() .keys(["k1", "k2"]) .query(); - expect(query).toEqual(test_queries[101][1]); + expect(query).toEqual(test_queries[107][1]); }); it(`QueryBuilder::search().from(1).where_().not().keys(["k1","k2"]).query()`, () => { @@ -763,12 +806,12 @@ describe("query tests", () => { .not() .keys(["k1", "k2"]) .query(); - expect(query).toEqual(test_queries[102][1]); + expect(query).toEqual(test_queries[108][1]); }); it(`QueryBuilder::search().from(1).where_().ids([1,2]).query()`, () => { let query = QueryBuilder.search().from(1).where().ids([1, 2]).query(); - expect(query).toEqual(test_queries[103][1]); + expect(query).toEqual(test_queries[109][1]); }); it(`QueryBuilder::search().from(1).where_().beyond().keys(["k"]).query()`, () => { @@ -778,7 +821,7 @@ describe("query tests", () => { .beyond() .keys(["k"]) .query(); - expect(query).toEqual(test_queries[104][1]); + expect(query).toEqual(test_queries[110][1]); }); it(`QueryBuilder::search().from(1).where_().not().ids([1,2]).query()`, () => { @@ -788,7 +831,7 @@ describe("query tests", () => { .not() .ids([1, 2]) .query(); - expect(query).toEqual(test_queries[105][1]); + expect(query).toEqual(test_queries[111][1]); }); it(`QueryBuilder::search().from(1).where_().not_beyond().ids("a").query()`, () => { @@ -798,7 +841,7 @@ describe("query tests", () => { .not_beyond() .ids("a") .query(); - expect(query).toEqual(test_queries[106][1]); + expect(query).toEqual(test_queries[112][1]); }); it(`QueryBuilder::search().from(1).where_().node().or().edge().query()`, () => { @@ -809,7 +852,7 @@ describe("query tests", () => { .or() .edge() .query(); - expect(query).toEqual(test_queries[107][1]); + expect(query).toEqual(test_queries[113][1]); }); it(`QueryBuilder::search().from(1).where_().node().and().distance(CountComparison::GreaterThanOrEqual(3)).query()`, () => { @@ -820,7 +863,7 @@ describe("query tests", () => { .and() .distance(CountComparison.GreaterThanOrEqual(3)) .query(); - expect(query).toEqual(test_queries[108][1]); + expect(query).toEqual(test_queries[114][1]); }); it(`QueryBuilder::search().from(1).where_().node().or().where_().edge().and().key("k").value(Comparison::Equal(1.into())).end_where().query()`, () => { @@ -836,7 +879,7 @@ describe("query tests", () => { .value(Comparison.Equal(1)) .end_where() .query(); - expect(query).toEqual(test_queries[109][1]); + expect(query).toEqual(test_queries[115][1]); }); it(`QueryBuilder::search().from(1).where_().node().or().where_().edge().and().key("k").value(Comparison::Contains(1.into())).end_where().query()`, () => { @@ -852,7 +895,7 @@ describe("query tests", () => { .value(Comparison.Contains(1)) .end_where() .query(); - expect(query).toEqual(test_queries[110][1]); + expect(query).toEqual(test_queries[116][1]); }); it(`QueryBuilder::search().from(1).where_().node().or().where_().edge().and().key("k").value(Comparison::Contains(([1,2]).into())).end_where().query()`, () => { @@ -868,7 +911,7 @@ describe("query tests", () => { .value(Comparison.Contains([1, 2])) .end_where() .query(); - expect(query).toEqual(test_queries[111][1]); + expect(query).toEqual(test_queries[117][1]); }); it(`QueryBuilder::search().from(1).order_by([DbKeyOrder::Asc("k".into())]).where_().node().query()`, () => { @@ -878,7 +921,7 @@ describe("query tests", () => { .where() .node() .query(); - expect(query).toEqual(test_queries[112][1]); + expect(query).toEqual(test_queries[118][1]); }); it(`QueryBuilder::search().from(1).limit(1).where_().node().query()`, () => { @@ -888,7 +931,7 @@ describe("query tests", () => { .where() .node() .query(); - expect(query).toEqual(test_queries[113][1]); + expect(query).toEqual(test_queries[119][1]); }); it(`QueryBuilder::search().from(1).offset(1).where_().node().query()`, () => { @@ -898,22 +941,22 @@ describe("query tests", () => { .where() .node() .query(); - expect(query).toEqual(test_queries[114][1]); + expect(query).toEqual(test_queries[120][1]); }); it(`QueryBuilder::search().to(1).offset(1).query()`, () => { let query = QueryBuilder.search().to(1).offset(1).query(); - expect(query).toEqual(test_queries[115][1]); + expect(query).toEqual(test_queries[121][1]); }); it(`QueryBuilder::search().to(1).limit(1).query()`, () => { let query = QueryBuilder.search().to(1).limit(1).query(); - expect(query).toEqual(test_queries[116][1]); + expect(query).toEqual(test_queries[122][1]); }); it(`QueryBuilder::search().to(1).where_().node().query()`, () => { let query = QueryBuilder.search().to(1).where().node().query(); - expect(query).toEqual(test_queries[117][1]); + expect(query).toEqual(test_queries[123][1]); }); it(`QueryBuilder::search().to(1).order_by([DbKeyOrder::Asc("k".into())]).where_().node().query()`, () => { @@ -923,6 +966,6 @@ describe("query tests", () => { .where() .node() .query(); - expect(query).toEqual(test_queries[118][1]); + expect(query).toEqual(test_queries[124][1]); }); }); diff --git a/agdb_server/src/api.rs b/agdb_server/src/api.rs index 4643a9da..59f98c42 100644 --- a/agdb_server/src/api.rs +++ b/agdb_server/src/api.rs @@ -237,6 +237,12 @@ QueryBuilder::select().ids("a").query(), QueryBuilder::select().ids([1, 2]).query(), QueryBuilder::select().ids(QueryBuilder::search().from(1).query()).query(), QueryBuilder::select().search().from(1).query(), +QueryBuilder::select().search().to(1).query(), +QueryBuilder::select().search().index("age").value(20).query(), +QueryBuilder::select().search().from("a").limit(10).query(), +QueryBuilder::select().search().from("a").offset(10).query(), +QueryBuilder::select().search().from("a").order_by(DbKeyOrder::Desc("age".into())).query(), +QueryBuilder::select().search().from("a").where_().node().query(), QueryBuilder::select().indexes().query(), QueryBuilder::select().keys().ids("a").query(), QueryBuilder::select().keys().ids([1, 2]).query(), diff --git a/agdb_server/test_queries.json b/agdb_server/test_queries.json index 05bec20b..dcbfdbdc 100644 --- a/agdb_server/test_queries.json +++ b/agdb_server/test_queries.json @@ -1925,6 +1925,173 @@ } } ], + [ + "QueryBuilder::select().search().to(1).query()", + { + "SelectValues": { + "keys": [], + "ids": { + "Search": { + "algorithm": "BreadthFirst", + "origin": { + "Id": 0 + }, + "destination": { + "Id": 1 + }, + "limit": 0, + "offset": 0, + "order_by": [], + "conditions": [] + } + } + } + } + ], + [ + "QueryBuilder::select().search().index(\"age\").value(20).query()", + { + "SelectValues": { + "keys": [], + "ids": { + "Search": { + "algorithm": "Index", + "origin": { + "Id": 0 + }, + "destination": { + "Id": 0 + }, + "limit": 0, + "offset": 0, + "order_by": [], + "conditions": [ + { + "logic": "And", + "modifier": "None", + "data": { + "KeyValue": { + "key": { + "String": "age" + }, + "value": { + "Equal": { + "I64": 20 + } + } + } + } + } + ] + } + } + } + } + ], + [ + "QueryBuilder::select().search().from(\"a\").limit(10).query()", + { + "SelectValues": { + "keys": [], + "ids": { + "Search": { + "algorithm": "BreadthFirst", + "origin": { + "Alias": "a" + }, + "destination": { + "Id": 0 + }, + "limit": 10, + "offset": 0, + "order_by": [], + "conditions": [] + } + } + } + } + ], + [ + "QueryBuilder::select().search().from(\"a\").offset(10).query()", + { + "SelectValues": { + "keys": [], + "ids": { + "Search": { + "algorithm": "BreadthFirst", + "origin": { + "Alias": "a" + }, + "destination": { + "Id": 0 + }, + "limit": 0, + "offset": 10, + "order_by": [], + "conditions": [] + } + } + } + } + ], + [ + "QueryBuilder::select().search().from(\"a\").order_by(DbKeyOrder::Desc(\"age\".into())).query()", + { + "SelectValues": { + "keys": [], + "ids": { + "Search": { + "algorithm": "BreadthFirst", + "origin": { + "Alias": "a" + }, + "destination": { + "Id": 0 + }, + "limit": 0, + "offset": 0, + "order_by": [ + { + "Desc": { + "String": "age" + } + } + ], + "conditions": [] + } + } + } + } + ], + [ + "QueryBuilder::select().search().from(\"a\").where_().node().query()", + { + "SelectValues": { + "keys": [], + "ids": { + "Search": { + "algorithm": "BreadthFirst", + "origin": { + "Alias": "a" + }, + "destination": { + "Id": 0 + }, + "limit": 0, + "offset": 0, + "order_by": [], + "conditions": [ + { + "logic": "And", + "modifier": "None", + "data": "Node" + } + ] + } + } + } + } + ], [ "QueryBuilder::select().indexes().query()", { diff --git a/agdb_web/pages/api-docs/php.en-US.mdx b/agdb_web/pages/api-docs/php.en-US.mdx index 277790e1..9f4d23b3 100644 --- a/agdb_web/pages/api-docs/php.en-US.mdx +++ b/agdb_web/pages/api-docs/php.en-US.mdx @@ -120,39 +120,39 @@ To execute queries against the database we call `dbExec` with the user and their ```php // Prepare the queries to be executed on the remote database. -let queries = [ - // :0: Inserts a root node aliased "users" - QueryBuilder.insert().nodes().aliases(["users"]).query(), - - // :1: Inserts more nodes with some data - QueryBuilder.insert() - .nodes() - .values([ - [ - "username" => "user1", - "password" => "password123", - ], - [ - "username" => "user2", - "password" => "password456", - ], - ]) - .query(), - - // :2: Connect the root to the inserted nodes with edges referencing both from previous queries - QueryBuilder.insert().edges().from(":0").to(":1").query(), - - // :3: Find a node starting at the "users" node (could also be ":0" in this instance) with specific username - QueryBuilder.select() - .ids( - QueryBuilder.search() - .from("users") - .where() - .key("username") - .value(Comparison.Equal("user1")) - .query() - ) - .query(), +$queries = [ + // :0: Inserts a root node aliased "users". + QueryBuilder::insert() + ->nodes() + ->aliases(["users"]) + ->query(), + + // :1: Inserts more nodes with some data. + QueryBuilder::insert() + ->nodes() + ->values([ + [ + "username" => "user1", + "password" => "password123", + ], + [ + "username" => "user2", + "password" => "password456", + ], + ]) + ->query(), + + // :2: Connect the root to the inserted nodes with edges referencing both from previous queries. + QueryBuilder::insert()->edges()->from(":0")->to(":1")->query(), + + // :3: Find a node starting at the "users" node (could also be ":0" in this instance) with specific username. + QueryBuilder::select() + ->search() + ->from("users") + ->where() + ->key("username") + ->value(ComparisonBuilder::Equal("user1")) + ->query() ]; // Execute queries. diff --git a/examples/server_client_php/src/index.php b/examples/server_client_php/src/index.php index ce75335f..5548e3c2 100644 --- a/examples/server_client_php/src/index.php +++ b/examples/server_client_php/src/index.php @@ -9,29 +9,29 @@ use Agnesoft\AgdbApi\QueryBuilder; use Agnesoft\AgdbApi\ComparisonBuilder; -// Defayult config will look for the server at http://localhost:3000 +// Default config will look for the server at http://localhost:3000 $config = Agnesoft\AgdbApi\Configuration::getDefaultConfiguration(); -// Using GuzzleHttp client. You can use any other like Symfony. +// Using GuzzleHttp client. You can use any other such as Symfony. $client = new AgdbApi(new GuzzleHttp\Client(), $config); // Runs the status query against the database // and throws if the server is not accessible. $client->status(); -// Login as server admin +// Login as server admin. $token = $client->userLogin( new UserLogin(["username" => "admin", "password" => "admin"]) ); $client->getConfig()->setAccessToken($token); -// Creat user "php_user1" +// Creat user "php_user1". $client->adminUserAdd( "php_user1", new UserCredentials(["password" => "php_user1"]) ); -// Login as "php_user1" +// Login as "php_user1". $token = $client->userLogin( new UserLogin([ "username" => "php_user1", @@ -40,18 +40,18 @@ ); $client->getConfig()->setAccessToken($token); -// Creates memory mapped database "db1" for user "php_user1" +// Creates memory mapped database "db1" for user "php_user1". $client->dbAdd("php_user1", "db1", DbType::MAPPED); // @phpstan-ignore argument.type // Prepare the queries to be executed on the remote database. $queries = [ - // :0: Inserts a root node aliased "users" + // :0: Inserts a root node aliased "users". QueryBuilder::insert() ->nodes() ->aliases(["users"]) ->query(), - // :1: Inserts more nodes with some data + // :1: Inserts more nodes with some data. QueryBuilder::insert() ->nodes() ->values([ @@ -66,10 +66,10 @@ ]) ->query(), - // :2: Connect the root to the inserted nodes with edges referencing both from previous queries + // :2: Connect the root to the inserted nodes with edges referencing both from previous queries. QueryBuilder::insert()->edges()->from(":0")->to(":1")->query(), - // :3: Find a node starting at the "users" node (could also be ":0" in this instance) with specific username + // :3: Find a node starting at the "users" node (could also be ":0" in this instance) with specific username. QueryBuilder::select() ->ids( QueryBuilder::search() @@ -82,10 +82,10 @@ ->query(), ]; -// Execute the queries +// Execute the queries. $result = $client->dbExec("php_user1", "db1", $queries); -// Print the result of the last query +// Print the result of the last query. printf($result[3]); // {