mirror of https://gitee.com/bigwinds/arangodb
868 lines
31 KiB
Plaintext
868 lines
31 KiB
Plaintext
!CHAPTER Fluent AQL Interface
|
|
|
|
This chapter describes a fluent interface to query [your graph](../Graphs/README.md).
|
|
The philosophy of this interface is to select a group of starting elements (vertices or edges) at first and from there on explore the graph with your query by selecting connected elements.
|
|
|
|
As an example you can start with a set of vertices, select their direct neighbors and finally their outgoing edges.
|
|
|
|
The result of this query will be the set of outgoing edges.
|
|
For each part of the query it is possible to further refine the resulting set of elements by giving examples for them.
|
|
|
|
Examples will explain the API on the [social graph](../Graphs/README.md#the-social-graph):
|
|
|
|

|
|
|
|
!SECTION Definition of examples
|
|
|
|
@startDocuBlock JSF_general_graph_example_description
|
|
|
|
!SECTION Starting Points
|
|
|
|
This section describes the entry points for the fluent interface.
|
|
The philosophy of this module is to start with a specific subset of vertices or edges and from there on iterate over the graph.
|
|
|
|
Therefore you get exactly this two entry points:
|
|
|
|
* Select a set of edges
|
|
* Select a set of vertices
|
|
|
|
!SUBSECTION Edges
|
|
|
|
|
|
|
|
@brief Select some edges from the graph.
|
|
|
|
`graph._edges(examples)`
|
|
|
|
Creates an AQL statement to select a subset of the edges stored in the graph.
|
|
This is one of the entry points for the fluent AQL interface.
|
|
It will return a mutable AQL statement which can be further refined, using the
|
|
functions described below.
|
|
The resulting set of edges can be filtered by defining one or more *examples*.
|
|
|
|
@PARAMS
|
|
|
|
@PARAM{examples, object, optional}
|
|
See [Definition of examples](#definition-of-examples)
|
|
|
|
@EXAMPLES
|
|
|
|
In the examples the *toArray* function is used to print the result.
|
|
The description of this function can be found below.
|
|
|
|
@startDocuBlockInline generalGraphEdgesUnfiltered
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphEdgesUnfiltered}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
graph._edges().toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphEdgesUnfiltered
|
|
|
|
To request filtered edges:
|
|
|
|
@startDocuBlockInline generalGraphEdgesFiltered
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphEdgesFiltered}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
graph._edges({type: "married"}).toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphEdgesFiltered
|
|
|
|
|
|
!SUBSECTION Vertices
|
|
|
|
|
|
|
|
@brief Select some vertices from the graph.
|
|
|
|
`graph._vertices(examples)`
|
|
|
|
Creates an AQL statement to select a subset of the vertices stored in the graph.
|
|
This is one of the entry points for the fluent AQL interface.
|
|
It will return a mutable AQL statement which can be further refined, using the
|
|
functions described below.
|
|
The resulting set of edges can be filtered by defining one or more *examples*.
|
|
|
|
@PARAMS
|
|
|
|
@PARAM{examples, object, optional}
|
|
See [Definition of examples](#definition-of-examples)
|
|
|
|
@EXAMPLES
|
|
|
|
In the examples the *toArray* function is used to print the result.
|
|
The description of this function can be found below.
|
|
|
|
To request unfiltered vertices:
|
|
|
|
@startDocuBlockInline generalGraphVerticesUnfiltered
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphVerticesUnfiltered}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
graph._vertices().toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphVerticesUnfiltered
|
|
|
|
To request filtered vertices:
|
|
|
|
@startDocuBlockInline generalGraphVerticesFiltered
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphVerticesFiltered}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
graph._vertices([{name: "Alice"}, {name: "Bob"}]).toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphVerticesFiltered
|
|
|
|
|
|
!SECTION Working with the query cursor
|
|
|
|
The fluent query object handles cursor creation and maintenance for you.
|
|
A cursor will be created as soon as you request the first result.
|
|
If you are unhappy with the current result and want to refine it further you can execute a further step in the query which cleans up the cursor for you.
|
|
In this interface you get the complete functionality available for general AQL cursors directly on your query.
|
|
The cursor functionality is described in this section.
|
|
|
|
!SUBSECTION ToArray
|
|
|
|
|
|
|
|
@brief Returns an array containing the complete result.
|
|
|
|
`graph_query.toArray()`
|
|
|
|
This function executes the generated query and returns the
|
|
entire result as one array.
|
|
ToArray does not return the generated query anymore and
|
|
hence can only be the endpoint of a query.
|
|
However keeping a reference to the query before
|
|
executing allows to chain further statements to it.
|
|
|
|
@EXAMPLES
|
|
|
|
To collect the entire result of a query toArray can be used:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLToArray
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLToArray}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._vertices();
|
|
query.toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLToArray
|
|
|
|
|
|
!SUBSECTION HasNext
|
|
|
|
|
|
|
|
@brief Checks if the query has further results.
|
|
|
|
`graph_query.hasNext()`
|
|
|
|
The generated statement maintains a cursor for you.
|
|
If this cursor is already present *hasNext()* will
|
|
use this cursors position to determine if there are
|
|
further results available.
|
|
If the query has not yet been executed *hasNext()*
|
|
will execute it and create the cursor for you.
|
|
|
|
@EXAMPLES
|
|
|
|
Start query execution with hasNext:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLHasNext
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLHasNext}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._vertices();
|
|
query.hasNext();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLHasNext
|
|
|
|
Iterate over the result as long as it has more elements:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLHasNextIteration
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLHasNextIteration}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._vertices();
|
|
| while (query.hasNext()) {
|
|
| var entry = query.next();
|
|
| // Do something with the entry
|
|
}
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLHasNextIteration
|
|
|
|
|
|
!SUBSECTION Next
|
|
|
|
|
|
|
|
@brief Request the next element in the result.
|
|
|
|
`graph_query.next()`
|
|
|
|
The generated statement maintains a cursor for you.
|
|
If this cursor is already present *next()* will
|
|
use this cursors position to deliver the next result.
|
|
Also the cursor position will be moved by one.
|
|
If the query has not yet been executed *next()*
|
|
will execute it and create the cursor for you.
|
|
It will throw an error of your query has no further results.
|
|
|
|
@EXAMPLES
|
|
|
|
Request some elements with next:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLNext
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLNext}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._vertices();
|
|
query.next();
|
|
query.next();
|
|
query.next();
|
|
query.next();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLNext
|
|
|
|
The cursor is recreated if the query is changed:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLNextRecreate
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLNextRecreate}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._vertices();
|
|
query.next();
|
|
query.edges();
|
|
query.next();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLNextRecreate
|
|
|
|
|
|
!SUBSECTION Count
|
|
|
|
|
|
|
|
@brief Returns the number of returned elements if the query is executed.
|
|
|
|
`graph_query.count()`
|
|
|
|
This function determines the amount of elements to be expected within the result of the query.
|
|
It can be used at the beginning of execution of the query
|
|
before using *next()* or in between *next()* calls.
|
|
The query object maintains a cursor of the query for you.
|
|
*count()* does not change the cursor position.
|
|
|
|
@EXAMPLES
|
|
|
|
To count the number of matched elements:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLCount
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLCount}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._vertices();
|
|
query.count();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLCount
|
|
|
|
|
|
!SECTION Fluent queries
|
|
|
|
After the selection of the entry point you can now query your graph in
|
|
a fluent way, meaning each of the functions on your query returns the query again.
|
|
Hence it is possible to chain arbitrary many executions one after the other.
|
|
In this section all available query statements are described.
|
|
|
|
!SUBSECTION Edges
|
|
|
|
|
|
|
|
@brief Select all edges for the vertices selected before.
|
|
|
|
`graph_query.edges(examples)`
|
|
|
|
Creates an AQL statement to select all edges for each of the vertices selected
|
|
in the step before.
|
|
This will include *inbound* as well as *outbound* edges.
|
|
The resulting set of edges can be filtered by defining one or more *examples*.
|
|
|
|
The complexity of this method is **O(n\*m^x)** with *n* being the vertices defined by the
|
|
parameter vertexExamplex, *m* the average amount of edges of a vertex and *x* the maximal depths.
|
|
Hence the default call would have a complexity of **O(n\*m)**;
|
|
|
|
@PARAMS
|
|
|
|
@PARAM{examples, object, optional}
|
|
See [Definition of examples](#definition-of-examples)
|
|
|
|
@EXAMPLES
|
|
|
|
To request unfiltered edges:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLEdgesUnfiltered
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLEdgesUnfiltered}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._vertices([{name: "Alice"}, {name: "Bob"}]);
|
|
query.edges().toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLEdgesUnfiltered
|
|
|
|
To request filtered edges by a single example:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLEdgesFilteredSingle
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLEdgesFilteredSingle}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._vertices([{name: "Alice"}, {name: "Bob"}]);
|
|
query.edges({type: "married"}).toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLEdgesFilteredSingle
|
|
|
|
To request filtered edges by multiple examples:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLEdgesFilteredMultiple
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLEdgesFilteredMultiple}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._vertices([{name: "Alice"}, {name: "Bob"}]);
|
|
query.edges([{type: "married"}, {type: "friend"}]).toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLEdgesFilteredMultiple
|
|
|
|
|
|
!SUBSECTION OutEdges
|
|
|
|
|
|
|
|
@brief Select all outbound edges for the vertices selected before.
|
|
|
|
`graph_query.outEdges(examples)`
|
|
|
|
Creates an AQL statement to select all *outbound* edges for each of the vertices selected
|
|
in the step before.
|
|
The resulting set of edges can be filtered by defining one or more *examples*.
|
|
|
|
@PARAMS
|
|
|
|
@PARAM{examples, object, optional}
|
|
See [Definition of examples](#definition-of-examples)
|
|
|
|
@EXAMPLES
|
|
|
|
To request unfiltered outbound edges:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLOutEdgesUnfiltered
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLOutEdgesUnfiltered}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._vertices([{name: "Alice"}, {name: "Bob"}]);
|
|
query.outEdges().toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLOutEdgesUnfiltered
|
|
|
|
To request filtered outbound edges by a single example:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLOutEdgesFilteredSingle
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLOutEdgesFilteredSingle}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._vertices([{name: "Alice"}, {name: "Bob"}]);
|
|
query.outEdges({type: "married"}).toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLOutEdgesFilteredSingle
|
|
|
|
To request filtered outbound edges by multiple examples:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLOutEdgesFilteredMultiple
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLOutEdgesFilteredMultiple}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._vertices([{name: "Alice"}, {name: "Bob"}]);
|
|
query.outEdges([{type: "married"}, {type: "friend"}]).toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLOutEdgesFilteredMultiple
|
|
|
|
|
|
!SUBSECTION InEdges
|
|
|
|
|
|
|
|
@brief Select all inbound edges for the vertices selected before.
|
|
|
|
`graph_query.inEdges(examples)`
|
|
|
|
|
|
Creates an AQL statement to select all *inbound* edges for each of the vertices selected
|
|
in the step before.
|
|
The resulting set of edges can be filtered by defining one or more *examples*.
|
|
|
|
@PARAMS
|
|
|
|
@PARAM{examples, object, optional}
|
|
See [Definition of examples](#definition-of-examples)
|
|
|
|
@EXAMPLES
|
|
|
|
To request unfiltered inbound edges:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLInEdgesUnfiltered
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLInEdgesUnfiltered}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._vertices([{name: "Alice"}, {name: "Bob"}]);
|
|
query.inEdges().toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLInEdgesUnfiltered
|
|
|
|
To request filtered inbound edges by a single example:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLInEdgesFilteredSingle
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLInEdgesFilteredSingle}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._vertices([{name: "Alice"}, {name: "Bob"}]);
|
|
query.inEdges({type: "married"}).toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLInEdgesFilteredSingle
|
|
|
|
To request filtered inbound edges by multiple examples:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLInEdgesFilteredMultiple
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLInEdgesFilteredMultiple}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._vertices([{name: "Alice"}, {name: "Bob"}]);
|
|
query.inEdges([{type: "married"}, {type: "friend"}]).toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLInEdgesFilteredMultiple
|
|
|
|
|
|
!SUBSECTION Vertices
|
|
|
|
|
|
|
|
@brief Select all vertices connected to the edges selected before.
|
|
|
|
`graph_query.vertices(examples)`
|
|
|
|
Creates an AQL statement to select all vertices for each of the edges selected
|
|
in the step before.
|
|
This includes all vertices contained in *_from* as well as *_to* attribute of the edges.
|
|
The resulting set of vertices can be filtered by defining one or more *examples*.
|
|
|
|
@PARAMS
|
|
|
|
@PARAM{examples, object, optional}
|
|
See [Definition of examples](#definition-of-examples)
|
|
|
|
@EXAMPLES
|
|
|
|
To request unfiltered vertices:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLVerticesUnfiltered
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLVerticesUnfiltered}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._edges({type: "married"});
|
|
query.vertices().toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLVerticesUnfiltered
|
|
|
|
To request filtered vertices by a single example:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLVerticesFilteredSingle
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLVerticesFilteredSingle}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._edges({type: "married"});
|
|
query.vertices({name: "Alice"}).toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLVerticesFilteredSingle
|
|
|
|
To request filtered vertices by multiple examples:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLVerticesFilteredMultiple
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLVerticesFilteredMultiple}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._edges({type: "married"});
|
|
query.vertices([{name: "Alice"}, {name: "Charly"}]).toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLVerticesFilteredMultiple
|
|
|
|
|
|
!SUBSECTION FromVertices
|
|
|
|
|
|
|
|
@brief Select all source vertices of the edges selected before.
|
|
|
|
`graph_query.fromVertices(examples)`
|
|
|
|
Creates an AQL statement to select the set of vertices where the edges selected
|
|
in the step before start at.
|
|
This includes all vertices contained in *_from* attribute of the edges.
|
|
The resulting set of vertices can be filtered by defining one or more *examples*.
|
|
|
|
@PARAMS
|
|
|
|
@PARAM{examples, object, optional}
|
|
See [Definition of examples](#definition-of-examples)
|
|
|
|
@EXAMPLES
|
|
|
|
To request unfiltered source vertices:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLFromVerticesUnfiltered
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLFromVerticesUnfiltered}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._edges({type: "married"});
|
|
query.fromVertices().toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLFromVerticesUnfiltered
|
|
|
|
To request filtered source vertices by a single example:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLFromVerticesFilteredSingle
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLFromVerticesFilteredSingle}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._edges({type: "married"});
|
|
query.fromVertices({name: "Alice"}).toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLFromVerticesFilteredSingle
|
|
|
|
To request filtered source vertices by multiple examples:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLFromVerticesFilteredMultiple
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLFromVerticesFilteredMultiple}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._edges({type: "married"});
|
|
query.fromVertices([{name: "Alice"}, {name: "Charly"}]).toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLFromVerticesFilteredMultiple
|
|
|
|
|
|
!SUBSECTION ToVertices
|
|
|
|
|
|
|
|
@brief Select all vertices targeted by the edges selected before.
|
|
|
|
`graph_query.toVertices(examples)`
|
|
|
|
Creates an AQL statement to select the set of vertices where the edges selected
|
|
in the step before end in.
|
|
This includes all vertices contained in *_to* attribute of the edges.
|
|
The resulting set of vertices can be filtered by defining one or more *examples*.
|
|
|
|
@PARAMS
|
|
|
|
@PARAM{examples, object, optional}
|
|
See [Definition of examples](#definition-of-examples)
|
|
|
|
@EXAMPLES
|
|
|
|
To request unfiltered target vertices:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLToVerticesUnfiltered
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLToVerticesUnfiltered}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._edges({type: "married"});
|
|
query.toVertices().toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLToVerticesUnfiltered
|
|
|
|
To request filtered target vertices by a single example:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLToVerticesFilteredSingle
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLToVerticesFilteredSingle}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._edges({type: "married"});
|
|
query.toVertices({name: "Bob"}).toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLToVerticesFilteredSingle
|
|
|
|
To request filtered target vertices by multiple examples:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLToVerticesFilteredMultiple
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLToVerticesFilteredMultiple}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._edges({type: "married"});
|
|
query.toVertices([{name: "Bob"}, {name: "Diana"}]).toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLToVerticesFilteredMultiple
|
|
|
|
|
|
!SUBSECTION Neighbors
|
|
|
|
|
|
|
|
@brief Select all neighbors of the vertices selected in the step before.
|
|
|
|
`graph_query.neighbors(examples, options)`
|
|
|
|
Creates an AQL statement to select all neighbors for each of the vertices selected
|
|
in the step before.
|
|
The resulting set of vertices can be filtered by defining one or more *examples*.
|
|
|
|
@PARAMS
|
|
|
|
@PARAM{examples, object, optional}
|
|
See [Definition of examples](#definition-of-examples)
|
|
|
|
@PARAM{options, object, optional}
|
|
An object defining further options. Can have the following values:
|
|
* *direction*: The direction of the edges. Possible values are *outbound*, *inbound* and *any* (default).
|
|
* *edgeExamples*: Filter the edges to be followed, see [Definition of examples](#definition-of-examples)
|
|
* *edgeCollectionRestriction* : One or a list of edge-collection names that should be
|
|
considered to be on the path.
|
|
* *vertexCollectionRestriction* : One or a list of vertex-collection names that should be
|
|
considered on the intermediate vertex steps.
|
|
* *minDepth*: Defines the minimal number of intermediate steps to neighbors (default is 1).
|
|
* *maxDepth*: Defines the maximal number of intermediate steps to neighbors (default is 1).
|
|
|
|
@EXAMPLES
|
|
|
|
To request unfiltered neighbors:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLNeighborsUnfiltered
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLNeighborsUnfiltered}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._vertices({name: "Alice"});
|
|
query.neighbors().toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLToVerticesFilteredMultiple
|
|
|
|
To request filtered neighbors by a single example:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLNeighborsFilteredSingle
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLNeighborsFilteredSingle}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._vertices({name: "Alice"});
|
|
query.neighbors({name: "Bob"}).toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLNeighborsFilteredSingle
|
|
|
|
To request filtered neighbors by multiple examples:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLNeighborsFilteredMultiple
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLNeighborsFilteredMultiple}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._edges({type: "married"});
|
|
query.vertices([{name: "Bob"}, {name: "Charly"}]).toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLNeighborsFilteredMultiple
|
|
|
|
|
|
!SUBSECTION Restrict
|
|
|
|
|
|
|
|
@brief Restricts the last statement in the chain to return
|
|
only elements of a specified set of collections
|
|
|
|
`graph_query.restrict(restrictions)`
|
|
|
|
By default all collections in the graph are searched for matching elements
|
|
whenever vertices and edges are requested.
|
|
Using *restrict* after such a statement allows to restrict the search
|
|
to a specific set of collections within the graph.
|
|
Restriction is only applied to this one part of the query.
|
|
It does not effect earlier or later statements.
|
|
|
|
@PARAMS
|
|
|
|
@PARAM{restrictions, array, optional}
|
|
Define either one or a list of collections in the graph.
|
|
Only elements from these collections are taken into account for the result.
|
|
|
|
@EXAMPLES
|
|
|
|
Request all directly connected vertices unrestricted:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLUnrestricted
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLUnrestricted}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._vertices({name: "Alice"});
|
|
query.edges().vertices().toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLUnrestricted
|
|
|
|
Apply a restriction to the directly connected vertices:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLRestricted
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLRestricted}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._vertices({name: "Alice"});
|
|
query.edges().vertices().restrict("female").toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLRestricted
|
|
|
|
Restriction of a query is only valid for collections known to the graph:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLRestrictedUnknown
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLRestrictedUnknown}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._vertices({name: "Alice"});
|
|
query.edges().vertices().restrict(["female", "male", "products"]).toArray(); // xpError(ERROR_BAD_PARAMETER);
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLRestrictedUnknown
|
|
|
|
|
|
!SUBSECTION Filter
|
|
|
|
|
|
|
|
@brief Filter the result of the query
|
|
|
|
`graph_query.filter(examples)`
|
|
|
|
This can be used to further specfiy the expected result of the query.
|
|
The result set is reduced to the set of elements that matches the given *examples*.
|
|
|
|
@PARAMS
|
|
|
|
@PARAM{examples, object, optional}
|
|
See [Definition of examples](#definition-of-examples)
|
|
|
|
@EXAMPLES
|
|
|
|
Request vertices unfiltered:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLUnfilteredVertices
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLUnfilteredVertices}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._edges({type: "married"});
|
|
query.toVertices().toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLUnfilteredVertices
|
|
|
|
Request vertices filtered:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLFilteredVertices
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLFilteredVertices}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._edges({type: "married"});
|
|
query.toVertices().filter({name: "Alice"}).toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLFilteredVertices
|
|
|
|
Request edges unfiltered:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLUnfilteredEdges
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLUnfilteredEdges}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._edges({type: "married"});
|
|
query.toVertices().outEdges().toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLUnfilteredEdges
|
|
|
|
Request edges filtered:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLFilteredEdges
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLFilteredEdges}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._edges({type: "married"});
|
|
query.toVertices().outEdges().filter({type: "married"}).toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLFilteredEdges
|
|
|
|
|
|
!SUBSECTION Path
|
|
|
|
|
|
|
|
@brief The result of the query is the path to all elements.
|
|
|
|
`graph_query.path()`
|
|
|
|
By defaut the result of the generated AQL query is the set of elements passing the last matches.
|
|
So having a `vertices()` query as the last step the result will be set of vertices.
|
|
Using `path()` as the last action before requesting the result
|
|
will modify the result such that the path required to find the set vertices is returned.
|
|
|
|
@EXAMPLES
|
|
|
|
Request the iteratively explored path using vertices and edges:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLPathSimple
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLPathSimple}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._vertices({name: "Alice"});
|
|
query.outEdges().toVertices().path().toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLPathSimple
|
|
|
|
When requesting neighbors the path to these neighbors is expanded:
|
|
|
|
@startDocuBlockInline generalGraphFluentAQLPathNeighbors
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLPathNeighbors}
|
|
var examples = require("@arangodb/graph-examples/example-graph.js");
|
|
var graph = examples.loadGraph("social");
|
|
var query = graph._vertices({name: "Alice"});
|
|
query.neighbors().path().toArray();
|
|
~ examples.dropGraph("social");
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
@endDocuBlock generalGraphFluentAQLPathNeighbors
|
|
|
|
|