mirror of https://gitee.com/bigwinds/arangodb
Add initial docs 'Coming from SQL'
This commit is contained in:
parent
f3422d96a6
commit
ae7554a9e1
|
@ -19,17 +19,17 @@ Here is an example document:
|
||||||
{
|
{
|
||||||
"_id" : "myusers/3456789",
|
"_id" : "myusers/3456789",
|
||||||
"_key" : "3456789",
|
"_key" : "3456789",
|
||||||
"_rev" : "3456789",
|
"_rev" : "14253647",
|
||||||
"firstName" : "Hugo",
|
"firstName" : "John",
|
||||||
"lastName" : "Schlonz",
|
"lastName" : "Doe",
|
||||||
"address" : {
|
"address" : {
|
||||||
"street" : "Street of Happiness",
|
"street" : "Road To Nowhere 1",
|
||||||
"city" : "Heretown"
|
"city" : "Gotham"
|
||||||
},
|
},
|
||||||
"hobbies" : [
|
"hobbies" : [
|
||||||
"swimming",
|
{name: "swimming", howFavorite: 10},
|
||||||
"biking",
|
{name: "biking", howFavorite: 6},
|
||||||
"programming"
|
{name: "programming", howFavorite: 4}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
@ -13,21 +13,21 @@ Any transaction only ever sees a single revision of a document.
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
"firstName" : "Hugo",
|
"_id" : "myusers/3456789",
|
||||||
"lastName" : "Schlonz",
|
"_key" : "3456789",
|
||||||
"address" : {
|
"_rev" : "14253647",
|
||||||
"city" : "Hier",
|
"firstName" : "John",
|
||||||
"street" : "Strasse 1"
|
"lastName" : "Doe",
|
||||||
},
|
"address" : {
|
||||||
"hobbies" : [
|
"street" : "Road To Nowhere 1",
|
||||||
"swimming",
|
"city" : "Gotham"
|
||||||
"biking",
|
},
|
||||||
"programming"
|
"hobbies" : [
|
||||||
],
|
{name: "swimming", howFavorite: 10},
|
||||||
"_id" : "demo/schlonz",
|
{name: "biking", howFavorite: 6},
|
||||||
"_rev" : "13728680",
|
{name: "programming", howFavorite: 4}
|
||||||
"_key" : "schlonz"
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,117 @@
|
||||||
|
!CHAPTER Coming from SQL
|
||||||
|
|
||||||
|
!SUBSECTION How do browse vectors translate into document queries?
|
||||||
|
|
||||||
|
In traditional SQL you may either fetch all columns of a table row by row, using
|
||||||
|
`SELECT * FROM table`, or select a subset of the columns. The list of table
|
||||||
|
columns to fetch is commonly called *column list* or *browse vector*:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT columnA, columnB, columnZ FROM table
|
||||||
|
```
|
||||||
|
|
||||||
|
Since documents aren't two-dimensional, and neither do you want to be limited to
|
||||||
|
returning two-dimensional lists, the requirements for a query language are higher.
|
||||||
|
AQL is thus a little bit more complex than plain SQL at first, but offers much
|
||||||
|
more flexibility in the long run. It lets you handle arbitrarily structured
|
||||||
|
documents in convenient ways, mostly leaned on the syntax used in JavaScript.
|
||||||
|
|
||||||
|
!SUBSUBSECTION Composing the documents to be returned
|
||||||
|
|
||||||
|
The AQL `RETURN` statement returns one item per document it is handed. You can
|
||||||
|
return the whole document, or just parts of it. Given that *oneDocument* is
|
||||||
|
a document (retrieved like `LET oneDocument = DOCUMENT("myusers/3456789")`
|
||||||
|
for instance), it can be returned as-is like this:
|
||||||
|
|
||||||
|
```js
|
||||||
|
RETURN oneDocument
|
||||||
|
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"_id" : "myusers/3456789",
|
||||||
|
"_key" : "3456789"
|
||||||
|
"_rev" : "14253647",
|
||||||
|
"firstName" : "John",
|
||||||
|
"lastName" : "Doe",
|
||||||
|
"address" : {
|
||||||
|
"city" : "Gotham",
|
||||||
|
"street" : "Road To Nowhere 1"
|
||||||
|
},
|
||||||
|
"hobbies" : [
|
||||||
|
{name: "swimming", howFavourite: 10},
|
||||||
|
{name: "biking", howFavourite: 6},
|
||||||
|
{name: "programming", howFavourite: 4}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
Return the hobbies sub-structure only:
|
||||||
|
|
||||||
|
```js
|
||||||
|
RETURN oneDocument.hobbies
|
||||||
|
```
|
||||||
|
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
[
|
||||||
|
{name: "swimming", howFavourite: 10},
|
||||||
|
{name: "biking", howFavourite: 6},
|
||||||
|
{name: "programming", howFavourite: 4}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
Return the hobbies and the address:
|
||||||
|
|
||||||
|
```js
|
||||||
|
RETURN {
|
||||||
|
hobbies: oneDocument.hobbies,
|
||||||
|
address: oneDocument.address
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
hobbies: [
|
||||||
|
{name: "swimming", howFavourite: 10},
|
||||||
|
{name: "biking", howFavourite: 6},
|
||||||
|
{name: "programming", howFavourite: 4}
|
||||||
|
],
|
||||||
|
address: {
|
||||||
|
"city" : "Gotham",
|
||||||
|
"street" : "Road To Nowhere 1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
Return the first hobby only:
|
||||||
|
|
||||||
|
```js
|
||||||
|
RETURN oneDocument.hobbies[0].name
|
||||||
|
```
|
||||||
|
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
"swimming"
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
Return a list of all hobby strings:
|
||||||
|
|
||||||
|
```js
|
||||||
|
RETURN { hobbies: oneDocument.hobbies[*].name }
|
||||||
|
```
|
||||||
|
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{hobbies: ["swimming", "biking", "porgramming"] }
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
More complex [array](../../AQL/Functions/Array.md) and
|
||||||
|
[object manipulations](../../AQL/Functions/Document.md) can be done using
|
||||||
|
AQL functions and [operators](../../AQL/Operators.md).
|
Loading…
Reference in New Issue