Skip to content

Commit 4861573

Browse files
author
Joohwan Oh
committed
Update README.md
1 parent d229583 commit 4861573

File tree

1 file changed

+104
-27
lines changed

1 file changed

+104
-27
lines changed

README.md

Lines changed: 104 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ Driver for ArangoDB REST API
88

99
python-arango is a driver for ArangoDB (https://www.arangodb.com/) REST API
1010

11-
## Installation (will be in PyPi soon)
11+
## Installation (will also be in PyPi soon)
1212

1313
```bash
1414
git clone https://github.com/Joowani/python-arango.git
1515
cd python-arango
1616
python2.7 setup.py install
1717
```
1818

19-
## Initializing ArangoDB Connection
19+
## Initializing Connection
2020
```python
2121
from arango import Arango
2222

@@ -42,13 +42,16 @@ a.db("dbXX").is_system
4242
## AQL Functions
4343
```python
4444
my_db = a.db("my_db")
45-
# List the AQL functions that's defined in databse "my_db"
45+
46+
# List the AQL functions that's defined in database "my_db"
4647
my_db.aql_functions
48+
4749
# Add a new AQL function
4850
my_db.add_aql_function(
4951
"myfunctions::temperature::ctof",
5052
"function (celsius) { return celsius * 1.8 + 32; }"
5153
)
54+
5255
# Remove a AQL function
5356
my_db.remove_aql_function("myfunctions::temperature::ctof")
5457
```
@@ -57,8 +60,10 @@ my_db.remove_aql_function("myfunctions::temperature::ctof")
5760
```python
5861
# Retrieve the execution plan without executing it
5962
my_db.explain_query("FOR doc IN my_col doc")
63+
6064
# Validate the AQL query without executing it
6165
my_db.validate_query("FOR doc IN my_col doc")
66+
6267
# Execute the AQL query and iterate through the AQL cursor
6368
cursor = my_db.execute_query(
6469
"FOR d IN my_col FILTER d.value == @val RETURN d",
@@ -71,14 +76,19 @@ for doc in cursor: # the cursor is deleted when the generator is exhausted
7176
## Collections
7277
```python
7378
my_db = a.db("my_db")
79+
7480
# List the collection names in "my_db"
7581
my_db.collections
82+
7683
# Add a new collection
7784
my_db.add_collection("new_col")
85+
7886
# Add a new edge collection
7987
my_db.add_collection("new_ecol", is_edge=True)
88+
8089
# Rename a collection
8190
my_db.rename_collection("new_col", "my_col")
91+
8292
# Remove a collection from the database
8393
my_db.remove_collection("my_col")
8494

@@ -99,21 +109,25 @@ my_col.revision
99109

100110
# Load the collection into memory
101111
my_col.load()
112+
102113
# Unload the collection from memory
103114
my_col.unload()
115+
104116
# Rotate the collection journal
105117
my_col.rotate_journal()
118+
106119
# Return the checksum of the collection
107120
my_col.checksum()
121+
108122
# Remove all documents in the collection
109123
my_col.truncate()
124+
110125
# Check if a document exists in the collection
111126
my_col.contains("a_document_key")
112127
"a_document_key" in my_col
113128
```
114129

115130
## Indexes
116-
117131
```python
118132
my_col = a.collection("my_col")
119133

@@ -138,68 +152,114 @@ my_col.add_fulltext_index(fields=["attr1"], min_length=10)
138152
```
139153

140154
## Documents
141-
142155
```python
143-
# Managing documents in a particular collection
144156
my_col = a.db("my_db").collection("my_col")
157+
158+
# Retrieve a document by its key
145159
my_col.get_document("doc01")
160+
161+
# Add a new document ("_key" attribute is optional)
146162
my_col.add_document({"_key": "doc01", "value": 1})
163+
164+
# Replace a document
147165
my_col.replace_document("doc01", {"value": 2})
166+
167+
# Update a document
148168
my_col.update_document("doc01", {"another_value": 3})
169+
170+
# Remove a document
149171
my_col.remove_document("doc01")
172+
173+
# Iterate through the documents in a collection and update them
150174
for doc in my_col:
151175
new_value = doc["value"] + 1
152176
my_col.update_document(doc["_key"], {"new_value": new_value})
153177
```
154178

155-
# Simple collection-specific queries
156-
my_col.first(5) # return the first 5 documents
157-
my_col.last(3) # return the last 3 documents
158-
my_col.all() # return all documents (generator object)
159-
my_col.any() # return a random document
160-
my_col.get_first_example({"value": 1}) # return first document whose "value" is 1
161-
my_col.get_by_example({"value": 1}) # return all documents whose "value" is 1
162-
my_col.update_by_example( # update all documents whose "value" is 1 with the new value
179+
## Simple (Collection-Specific) Queries
180+
```python
181+
# Return the first 5 documents in collection "my_col"
182+
my_col.first(5)
183+
184+
# Return the last 3 documents
185+
my_col.last(3)
186+
187+
# Return all documents (cursor generator object)
188+
my_col.all()
189+
190+
# Return a random document
191+
my_col.any()
192+
193+
# Return first document whose "value" is 1
194+
my_col.get_first_example({"value": 1})
195+
196+
# Return all documents whose "value" is 1
197+
my_col.get_by_example({"value": 1})
198+
199+
# Update all documents whose "value" is 1 with a new attribute
200+
my_col.update_by_example(
163201
{"value": 1},
164202
new_value={"new_attr": 1}
165203
)
166-
my_col.within(latitude=100, longitude=20, radius=15) # return all docs within (requires geo-index)
167-
my_col.near(latitude=100, longitude=20, radius=15) # return all docs near (requires geo-index)
168204

169-
# Managing Graphs
205+
# Return all docs within a radius around a given coordinate (requires geo-index)
206+
my_col.within(latitude=100, longitude=20, radius=15)
207+
208+
# Return all documents near a given coordinate (requires geo-index)
209+
my_col.near(latitude=100, longitude=20)
210+
```
211+
212+
## Graphs
213+
```python
170214
my_db = a.db("my_db")
171-
my_db.graphs # list all the graphs in the database
215+
# List all the graphs in the database
216+
my_db.graphs
217+
# Add a new graph
172218
my_graph = my_db.add_graph("my_graph")
173219

174-
# Adding vertex collections to a graph
220+
# Add new vertex collections to a graph
175221
my_db.add_collection("vcol01")
176222
my_db.add_collection("vcol02")
177223
my_graph.add_vertex_collection("vcol01")
178224
my_graph.add_vertex_collection("vcol02")
179225

180-
# Adding an edge definition to a graph
226+
# Add a new edge definition to a graph
181227
my_db.add_collection("ecol01", is_edge=True)
182228
my_graph.add_edge_definition(
183229
edge_collection="ecol01",
184230
from_vertex_collections=["vcol01"],
185231
to_vertex_collections=["vcol02"],
186232
)
187-
# Retrieving information from a graph
233+
234+
# Retrieve graph information
188235
my_graph.properties
189236
my_graph.id
190237
my_graph.revision
191238
my_graph.edge_definitions
192239
my_graph.vertex_collections
193240
my_graph.orphan_collections
241+
```
242+
194243

195-
# Managing vertices (needs valid vertex collections)
244+
## Vertice
245+
```python
246+
# Add new vertices
196247
my_graph.add_vertex("vcol01", {"_key": "v01", "value": 1})
197248
my_graph.add_vertex("vcol02", {"_key": "v01", "value": 1})
249+
250+
# Replace a vertex
198251
my_graph.replace_vertex("vol01/v01", {"value": 2})
252+
253+
# Update a vertex
199254
my_graph.update_vertex("vol02/v01", {"new_value": 3})
255+
256+
# Remove a vertex
200257
my_graph.remove_vertex("vol01/v01")
258+
```
201259

202-
# Managing edges (needs valid vertex and edge collections)
260+
## Edges
261+
```python
262+
# Add a new edge
203263
my_graph.add_edge(
204264
"ecol01",
205265
{
@@ -209,20 +269,38 @@ my_graph.add_edge(
209269
"value": 1,
210270
}
211271
)
272+
273+
# Replace an edge
212274
my_graph.replace_edge("ecol01/e01", {"new_value": 2})
275+
276+
# Update an edge
213277
my_graph.update_edge("ecol01/e01", {"value": 3})
278+
279+
# Remove an edge
214280
my_graph.remove_edge("ecol01/e01")
281+
```
215282

216-
# Graph traversals
283+
## Traversals
284+
```python
285+
# Execute a graph traversal
217286
results = my_graph.execute_traversal(
218287
start_vertex="vcol01/v01",
219288
direction="outbound",
220289
strategy="depthfirst"
221290
)
291+
292+
# Get the visited nodes in order
222293
results.get("visited")
294+
295+
# Get the paths traversed
223296
results.get("paths")
297+
```
298+
299+
## Batch Requests
300+
```python
301+
# NOTE: only (add/update/replace/remove) methods (documents/vertices/edges) are supported at the moment
224302

225-
# Batch Requests (only add, update, replace and remove methods are supported atm)
303+
# Execute a batch documents request
226304
my_db.execute_batch([
227305
(
228306
my_col.add_document, # method name
@@ -251,6 +329,7 @@ my_db.execute_batch([
251329
),
252330
])
253331

332+
# Execute a batch vertex requests
254333
self.db.execute_batch([
255334
(
256335
my_graph.add_vertex,
@@ -268,8 +347,6 @@ self.db.execute_batch([
268347
{"wait_for_sync": True}
269348
),
270349
])
271-
272-
273350
```
274351

275352
## Running System Tests (requires ArangoDB on localhost)

0 commit comments

Comments
 (0)