mirror of https://gitee.com/bigwinds/arangodb
241 lines
6.6 KiB
Plaintext
241 lines
6.6 KiB
Plaintext
!CHAPTER Fluent AQL Interface
|
|
|
|
This chapter describes a fluent interface to query your graph.
|
|
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.
|
|
|
|
!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
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_edges -->
|
|
|
|
!SUBSECTION Vertices
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_vertices -->
|
|
|
|
!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
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_toArray -->
|
|
|
|
!SUBSECTION HasNext
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_hasNext -->
|
|
|
|
!SUBSECTION Next
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_next -->
|
|
|
|
!SUBSECTION Count
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_count -->
|
|
|
|
!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
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_edges -->
|
|
|
|
`graph-query.edges(examples)`
|
|
*Select all edges for the vertices selected before.*
|
|
|
|
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:
|
|
|
|
* 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.
|
|
|
|
@EXAMPLES
|
|
|
|
To request unfiltered edges:
|
|
|
|
|
|
```
|
|
arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
|
|
arangosh> var g = examples.loadGraph("social");
|
|
arangosh> var query = g._vertices([{name: "Alice"}, {name: "Bob"}]);
|
|
arangosh> query.edges().toArray();
|
|
[
|
|
{
|
|
"_id" : "relation/31670695",
|
|
"_rev" : "31670695",
|
|
"_key" : "31670695",
|
|
"_from" : "female/30491047",
|
|
"_to" : "male/30884263",
|
|
"type" : "married"
|
|
},
|
|
{
|
|
"_id" : "relation/31932839",
|
|
"_rev" : "31932839",
|
|
"_key" : "31932839",
|
|
"_from" : "female/30491047",
|
|
"_to" : "male/31080871",
|
|
"type" : "friend"
|
|
},
|
|
{
|
|
"_id" : "relation/31670695",
|
|
"_rev" : "31670695",
|
|
"_key" : "31670695",
|
|
"_from" : "female/30491047",
|
|
"_to" : "male/30884263",
|
|
"type" : "married"
|
|
},
|
|
{
|
|
"_id" : "relation/32326055",
|
|
"_rev" : "32326055",
|
|
"_key" : "32326055",
|
|
"_from" : "male/30884263",
|
|
"_to" : "female/31277479",
|
|
"type" : "friend"
|
|
}
|
|
]
|
|
arangosh> examples.dropGraph("social");
|
|
undefined
|
|
```
|
|
<br />
|
|
To request filtered edges by a single example:
|
|
<br />
|
|
|
|
```
|
|
arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
|
|
arangosh> var g = examples.loadGraph("social");
|
|
arangosh> var query = g._vertices([{name: "Alice"}, {name: "Bob"}]);
|
|
arangosh> query.edges({type: "married"}).toArray();
|
|
[
|
|
{
|
|
"_id" : "relation/31670695",
|
|
"_rev" : "31670695",
|
|
"_key" : "31670695",
|
|
"_from" : "female/30491047",
|
|
"_to" : "male/30884263",
|
|
"type" : "married"
|
|
},
|
|
{
|
|
"_id" : "relation/31670695",
|
|
"_rev" : "31670695",
|
|
"_key" : "31670695",
|
|
"_from" : "female/30491047",
|
|
"_to" : "male/30884263",
|
|
"type" : "married"
|
|
}
|
|
]
|
|
arangosh> examples.dropGraph("social");
|
|
undefined
|
|
```
|
|
<br />
|
|
To request filtered edges by multiple examples:
|
|
<br />
|
|
|
|
```
|
|
arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
|
|
arangosh> var g = examples.loadGraph("social");
|
|
arangosh> var query = g._vertices([{name: "Alice"}, {name: "Bob"}]);
|
|
arangosh> query.edges([{type: "married"}, {type: "friend"}]).toArray();
|
|
[
|
|
{
|
|
"_id" : "relation/31670695",
|
|
"_rev" : "31670695",
|
|
"_key" : "31670695",
|
|
"_from" : "female/30491047",
|
|
"_to" : "male/30884263",
|
|
"type" : "married"
|
|
},
|
|
{
|
|
"_id" : "relation/31932839",
|
|
"_rev" : "31932839",
|
|
"_key" : "31932839",
|
|
"_from" : "female/30491047",
|
|
"_to" : "male/31080871",
|
|
"type" : "friend"
|
|
},
|
|
{
|
|
"_id" : "relation/31670695",
|
|
"_rev" : "31670695",
|
|
"_key" : "31670695",
|
|
"_from" : "female/30491047",
|
|
"_to" : "male/30884263",
|
|
"type" : "married"
|
|
},
|
|
{
|
|
"_id" : "relation/32326055",
|
|
"_rev" : "32326055",
|
|
"_key" : "32326055",
|
|
"_from" : "male/30884263",
|
|
"_to" : "female/31277479",
|
|
"type" : "friend"
|
|
}
|
|
]
|
|
arangosh> examples.dropGraph("social");
|
|
undefined
|
|
```
|
|
<!-- @endDocuBlock -->
|
|
|
|
!SUBSECTION OutEdges
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_outEdges -->
|
|
|
|
!SUBSECTION InEdges
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_inEdges -->
|
|
|
|
!SUBSECTION Vertices
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_vertices -->
|
|
|
|
!SUBSECTION FromVertices
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_fromVertices -->
|
|
|
|
!SUBSECTION ToVertices
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_toVertices -->
|
|
|
|
!SUBSECTION Neighbors
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_neighbors -->
|
|
|
|
!SUBSECTION Restrict
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_restrict -->
|
|
|
|
!SUBSECTION Filter
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_filter -->
|
|
|
|
!SUBSECTION Path
|
|
|
|
<!-- @startDocuBlock JSF_general_graph_fluent_aql_path -->
|