mirror of https://gitee.com/bigwinds/arangodb
736 lines
27 KiB
Plaintext
736 lines
27 KiB
Plaintext
!CHAPTER Fluent AQL Interface
|
|
|
|
This chapter describes a fluent interface to query your graph.
|
|
The philosophy of this interface is to at first select a group of starting elements (vertices or edges) 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.
|
|
|
|
!SECTION Starting Points
|
|
|
|
This section describes the entry points for the fluent interface.
|
|
In the philosophy of this module you have 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
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_edges -->
|
|
|
|
Select some edges from the graph.
|
|
<br />
|
|
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`.
|
|
<br />
|
|
`examples` can have the following values:
|
|
<br />
|
|
* Empty, there is no matching executed all edges are valid.
|
|
* A string, only the edge having this value as it's id is returned.
|
|
* An example object, defining a set of attributes.
|
|
Only edges having these attributes are matched.
|
|
* A list containing example objects and/or strings.
|
|
All edges matching at least one of the elements in the list are returned.
|
|
<br />
|
|
@EXAMPLES
|
|
<br />
|
|
In the examples the `toArray` function is used to print the result.
|
|
The description of this module can be found below.
|
|
<br />
|
|
To request unfiltered edges:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphEdgesUnfiltered}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
g._edges().toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<br />
|
|
To request filtered edges:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphEdgesUnfiltered}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
g._edges({type: "married"}).toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<!-- @endDocuBlock -->
|
|
|
|
!SUBSECTION Vertices
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_vertices -->
|
|
|
|
Select some vertices from the graph.
|
|
<br />
|
|
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`.
|
|
<br />
|
|
`examples` can have the following values:
|
|
<br />
|
|
* Empty, there is no matching executed all vertices are valid.
|
|
* A string, only the vertex having this value as it's id is returned.
|
|
* An example object, defining a set of attributes.
|
|
Only vertices having these attributes are matched.
|
|
* A list containing example objects and/or strings.
|
|
All vertices matching at least one of the elements in the list are returned.
|
|
<br />
|
|
@EXAMPLES
|
|
<br />
|
|
In the examples the `toArray` function is used to print the result.
|
|
The description of this module can be found below.
|
|
<br />
|
|
To request unfiltered vertices:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphVerticesUnfiltered}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
g._vertices().toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<br />
|
|
To request filtered vertices:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphVerticesUnfiltered}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
g._vertices([{name: "Alice"}, {name: "Bob"}]).toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<!-- @endDocuBlock -->
|
|
|
|
!SECTION Fluent query options
|
|
|
|
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.
|
|
The query object itself 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.
|
|
|
|
!SUBSECTION ToArray
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_toArray -->
|
|
|
|
Returns an array containing the complete result.
|
|
<br />
|
|
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.
|
|
<br />
|
|
@EXAMPLES
|
|
<br />
|
|
To collect the entire result of a query toArray can be used:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLToArray}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._vertices();
|
|
query.toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<!-- @endDocuBlock -->
|
|
|
|
!SUBSECTION HasNext
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_hasNext -->
|
|
|
|
Checks if the query has further results.
|
|
<br />
|
|
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.
|
|
<br />
|
|
@EXAMPLES
|
|
<br />
|
|
Start query execution with hasNext:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLToArray}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._vertices();
|
|
query.hasNext();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<br />
|
|
Iterate over the result as long as it has more elements:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLToArray}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._vertices();
|
|
while(query.hasNext()) {
|
|
query.next();
|
|
}
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<!-- @endDocuBlock -->
|
|
|
|
!SUBSECTION Next
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_next -->
|
|
|
|
Request the next element in the result
|
|
<br />
|
|
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.
|
|
<br />
|
|
@EXAMPLES
|
|
<br />
|
|
Request some elements with next:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLToArray}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._vertices();
|
|
query.next();
|
|
query.next();
|
|
query.next();
|
|
query.next();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<br />
|
|
The cursor is recreated if the query is changed.
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLToArray}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._vertices();
|
|
query.next();
|
|
query.edges();
|
|
query.next();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<!-- @endDocuBlock -->
|
|
|
|
!SUBSECTION Count
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_count -->
|
|
|
|
Returns the number of returned elements if the query is executed.
|
|
<br />
|
|
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.
|
|
<br />
|
|
@EXAMPLES
|
|
<br />
|
|
To count the number of matched elements:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLToArray}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._vertices();
|
|
query.count();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<!-- @endDocuBlock -->
|
|
|
|
!SUBSECTION Edges
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_edges -->
|
|
|
|
Select all edges for the vertices selected before
|
|
<br />
|
|
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`.
|
|
<br />
|
|
`examples` can have the following values:
|
|
<br />
|
|
* Empty, there is no matching executed all edges are valid.
|
|
* A string, only the edge having this value as it's id is returned.
|
|
* An example object, defining a set of attributes.
|
|
Only edges having these attributes are matched.
|
|
* A list containing example objects and/or strings.
|
|
All edges matching at least one of the elements in the list are returned.
|
|
<br />
|
|
@EXAMPLES
|
|
<br />
|
|
To request unfiltered edges:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLEdgesUnfiltered}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._vertices([{name: "Alice"}, {name: "Bob"}]);
|
|
query.edges().toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<br />
|
|
To request filtered edges by a single example:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLEdgesFilteredSingle}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._vertices([{name: "Alice"}, {name: "Bob"}]);
|
|
query.edges({type: "married"}).toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<br />
|
|
To request filtered edges by multiple examples:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLEdgesFilteredMultiple}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._vertices([{name: "Alice"}, {name: "Bob"}]);
|
|
query.edges([{type: "married"}, {type: "friend"}]).toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<!-- @endDocuBlock -->
|
|
|
|
!SUBSECTION OutEdges
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_outEdges -->
|
|
|
|
Select all outbound edges for the vertices selected before
|
|
<br />
|
|
`graph-query.outEdges(examples)`
|
|
<br />
|
|
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`.
|
|
<br />
|
|
`examples` can have the following values:
|
|
<br />
|
|
* Empty, there is no matching executed all edges are valid.
|
|
* A string, only the edge having this value as it's id is returned.
|
|
* An example object, defining a set of attributes.
|
|
Only edges having these attributes are matched.
|
|
* A list containing example objects and/or strings.
|
|
All edges matching at least one of the elements in the list are returned.
|
|
<br />
|
|
@EXAMPLES
|
|
<br />
|
|
To request unfiltered outbound edges:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLOutEdgesUnfiltered}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._vertices([{name: "Alice"}, {name: "Bob"}]);
|
|
query.outEdges().toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<br />
|
|
To request filtered outbound edges by a single example:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLOutEdgesFilteredSingle}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._vertices([{name: "Alice"}, {name: "Bob"}]);
|
|
query.outEdges({type: "married"}).toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<br />
|
|
To request filtered outbound edges by multiple examples:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLOutEdgesFilteredMultiple}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._vertices([{name: "Alice"}, {name: "Bob"}]);
|
|
query.outEdges([{type: "married"}, {type: "friend"}]).toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<!-- @endDocuBlock -->
|
|
|
|
!SUBSECTION InEdges
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_inEdges -->
|
|
|
|
Select all inbound edges for the vertices selected before
|
|
<br />
|
|
`graph-query.inEdges(examples)`
|
|
<br />
|
|
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`.
|
|
<br />
|
|
`examples` can have the following values:
|
|
<br />
|
|
* Empty, there is no matching executed all edges are valid.
|
|
* A string, only the edge having this value as it's id is returned.
|
|
* An example object, defining a set of attributes.
|
|
Only edges having these attributes are matched.
|
|
* A list containing example objects and/or strings.
|
|
All edges matching at least one of the elements in the list are returned.
|
|
<br />
|
|
@EXAMPLES
|
|
<br />
|
|
To request unfiltered inbound edges:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLInEdgesUnfiltered}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._vertices([{name: "Alice"}, {name: "Bob"}]);
|
|
query.inEdges().toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<br />
|
|
To request filtered inbound edges by a single example:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLInEdgesFilteredSingle}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._vertices([{name: "Alice"}, {name: "Bob"}]);
|
|
query.inEdges({type: "married"}).toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<br />
|
|
To request filtered inbound edges by multiple examples:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLInEdgesFilteredMultiple}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._vertices([{name: "Alice"}, {name: "Bob"}]);
|
|
query.inEdges([{type: "married"}, {type: "friend"}]).toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<!-- @endDocuBlock -->
|
|
|
|
!SUBSECTION Vertices
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_vertices -->
|
|
|
|
Select all vertices connected to the edges selected before
|
|
<br />
|
|
`graph-query.vertices(examples)`
|
|
<br />
|
|
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`.
|
|
<br />
|
|
`examples` can have the following values:
|
|
<br />
|
|
* Empty, there is no matching executed all vertices are valid.
|
|
* A string, only the vertex having this value as it's id is returned.
|
|
* An example object, defining a set of attributes.
|
|
Only vertices having these attributes are matched.
|
|
* A list containing example objects and/or strings.
|
|
All vertices matching at least one of the elements in the list are returned.
|
|
<br />
|
|
@EXAMPLES
|
|
<br />
|
|
To request unfiltered vertices:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLVerticesUnfiltered}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._edges({type: "married"});
|
|
query.vertices().toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<br />
|
|
To request filtered vertices by a single example:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLVerticesFilteredSingle}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._edges({type: "married"});
|
|
query.vertices({name: "Alice"}).toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<br />
|
|
To request filtered vertices by multiple examples:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLVerticesFilteredMultiple}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._edges({type: "married"});
|
|
query.vertices([{name: "Alice"}, {name: "Charly"}]).toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<!-- @endDocuBlock -->
|
|
|
|
!SUBSECTION FromVertices
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_fromVertices -->
|
|
|
|
Select all vertices where the edges selected before start
|
|
<br />
|
|
`graph-query.vertices(examples)`}
|
|
<br />
|
|
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`.
|
|
<br />
|
|
`examples` can have the following values:
|
|
<br />
|
|
* Empty, there is no matching executed all vertices are valid.
|
|
* A string, only the vertex having this value as it's id is returned.
|
|
* An example object, defining a set of attributes.
|
|
Only vertices having these attributes are matched.
|
|
* A list containing example objects and/or strings.
|
|
All vertices matching at least one of the elements in the list are returned.
|
|
<br />
|
|
@EXAMPLES
|
|
<br />
|
|
To request unfiltered starting vertices:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLFromVerticesUnfiltered}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._edges({type: "married"});
|
|
query.fromVertices().toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<br />
|
|
To request filtered starting vertices by a single example:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLFromVerticesFilteredSingle}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._edges({type: "married"});
|
|
query.fromVertices({name: "Alice"}).toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<br />
|
|
To request filtered starting vertices by multiple examples:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLFromVerticesFilteredMultiple}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._edges({type: "married"});
|
|
query.fromVertices([{name: "Alice"}, {name: "Charly"}]).toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<!-- @endDocuBlock -->
|
|
|
|
!SUBSECTION ToVertices
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_toVertices -->
|
|
|
|
Select all vertices targeted by the edges selected before
|
|
<br />
|
|
`graph-query.vertices(examples)`
|
|
<br />
|
|
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`.
|
|
<br />
|
|
`examples` can have the following values:
|
|
<br />
|
|
* Empty, there is no matching executed all vertices are valid.
|
|
* A string, only the vertex having this value as it's id is returned.
|
|
* An example object, defining a set of attributes.
|
|
Only vertices having these attributes are matched.
|
|
* A list containing example objects and/or strings.
|
|
All vertices matching at least one of the elements in the list are returned.
|
|
<br />
|
|
@EXAMPLES
|
|
<br />
|
|
To request unfiltered starting vertices:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLToVerticesUnfiltered}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._edges({type: "married"});
|
|
query.toVertices().toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<br />
|
|
To request filtered starting vertices by a single example:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLToVerticesFilteredSingle}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._edges({type: "married"});
|
|
query.toVertices({name: "Alice"}).toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<br />
|
|
To request filtered starting vertices by multiple examples:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLToVerticesFilteredMultiple}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._edges({type: "married"});
|
|
query.toVertices([{name: "Alice"}, {name: "Charly"}]).toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<!-- @endDocuBlock -->
|
|
|
|
!SUBSECTION Neighbors
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_neighbors -->
|
|
|
|
Select all neighbors of the vertices selected in the step before.
|
|
<br />
|
|
`graph-query.neighbors(examples)`
|
|
<br />
|
|
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`.
|
|
<br />
|
|
`examples` can have the following values:
|
|
<br />
|
|
* Empty, there is no matching executed all vertices are valid.
|
|
* A string, only the vertex having this value as it's id is returned.
|
|
* An example object, defining a set of attributes.
|
|
Only vertices having these attributes are matched.
|
|
* A list containing example objects and/or strings.
|
|
All vertices matching at least one of the elements in the list are returned.
|
|
<br />
|
|
@EXAMPLES
|
|
<br />
|
|
To request unfiltered neighbors:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLNeighborsUnfiltered}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._vertices({name: "Alice"});
|
|
query.neighbors().toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<br />
|
|
To request filtered neighbors by a single example:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLNeighborsFilteredSingle}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._vertices({name: "Alice"});
|
|
query.neighbors({name: "Bob"}).toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<br />
|
|
To request filtered neighbors by multiple examples:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLNeighborsFilteredMultiple}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._edges({type: "married"});
|
|
query.vertices([{name: "Bob"}, {name: "Charly"}]).toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<!-- @endDocuBlock -->
|
|
|
|
!SUBSECTION Restrict
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_restrict -->
|
|
|
|
Restricts the last statement in the chain to return
|
|
only elements of a specified set of collections
|
|
<br />
|
|
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.
|
|
<br />
|
|
`restrictions` can have the following values:
|
|
<br />
|
|
* A string defining the name of one specific collection in the graph.
|
|
Only elements from this collection are used for matching
|
|
* A list of strings defining a set of collection names.
|
|
Elements from all collections in this set are used for matching
|
|
<br />
|
|
@EXAMPLES
|
|
<br />
|
|
Request all directly connected vertices unrestricted:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLUnrestricted}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._vertices({name: "Alice"});
|
|
query.edges().vertices().toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<br />
|
|
Apply a restriction to the directly connected vertices:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLRestricted}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._vertices({name: "Alice"});
|
|
query.edges().vertices().restrict("female").toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<br />
|
|
Restriction of a query is only valid for collections known to the graph:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLRestricted}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._vertices({name: "Alice"});
|
|
query.edges().vertices().restrict(["female", "male", "products"]).toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<!-- @endDocuBlock -->
|
|
|
|
!SUBSECTION Filter
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_filter -->
|
|
|
|
Filter the result of the query
|
|
<br />
|
|
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`.
|
|
<br />
|
|
`examples` can have the following values:
|
|
<br />
|
|
* A string, only the elements having this value as it's id is returned.
|
|
* An example object, defining a set of attributes.
|
|
Only elements having these attributes are matched.
|
|
* A list containing example objects and/or strings.
|
|
All elements matching at least one of the elements in the list are returned.
|
|
<br />
|
|
@EXAMPLES
|
|
<br />
|
|
Request vertices unfiltered:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLUnfilteredVertices}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._edges({type: "married"});
|
|
query.toVertices().toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<br />
|
|
Request vertices filtered:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLFilteredVertices}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._edges({type: "married"});
|
|
query.toVertices().filter({name: "Alice"}).toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<br />
|
|
Request edges unfiltered:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLUnfilteredEdges}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._edges({type: "married"});
|
|
query.toVertices().outEdges().toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<br />
|
|
Request edges filtered:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLFilteredEdges}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._edges({type: "married"});
|
|
query.toVertices().outEdges().filter({type: "married"}).toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<!-- @endDocuBlock -->
|
|
|
|
!SUBSECTION Path
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_path -->
|
|
|
|
The result of the query is the path to all elements.
|
|
<br />
|
|
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.
|
|
<br />
|
|
@EXAMPLES
|
|
<br />
|
|
Request the iteratively explored path using vertices and edges:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLPathSimple}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._vertices({name: "Alice"});
|
|
query.outEdges().toVertices().path().toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<br />
|
|
When requesting neighbors the path to these neighbors is expanded:
|
|
<br />
|
|
@EXAMPLE_ARANGOSH_OUTPUT{generalGraphFluentAQLPathNeighbors}
|
|
var examples = require("orgarangodbgraph-examplesexample-graph.js");
|
|
var g = examples.loadGraph("social");
|
|
var query = g._vertices({name: "Alice"});
|
|
query.neighbors().path().toArray();
|
|
@END_EXAMPLE_ARANGOSH_OUTPUT
|
|
<!-- @endDocuBlock -->
|