@@ -27,23 +27,45 @@ a = Arango(host="localhost", port=8529)
2727## Databases
2828``` python
2929# List the database names
30+ a.databases
3031a.databases[" user" ]
3132a.databases[" system" ]
3233
33- # Retrieve database information
34- a.db(" _system" ).name
35- a.name # if db is not specified default database "_system" is used
34+ # Get information on the default database ("_system")
35+ a.name # equivalent to a.db("_system").name
36+ a.collections # equivalent to a.db("_system").collections
37+ a.id # equivalent to a.db("_system").id
38+ a.path # equivalent to a.db("_system").path
39+ a.is_system # equivalent to a.db("_system").is_system
40+
41+ # Get information on a specific database
3642a.db(" db01" ).collections
3743a.db(" db02" ).id
3844a.db(" db03" ).path
3945a.db(" dbXX" ).is_system
46+
47+ # Create a new database
48+ a.add_database(" my_db" )
49+
50+ # Remove a database
51+ a.remove_database(" my_db" )
52+
53+ # Working with database "_system"
54+ a.add_collection(" my_col" )
55+ a.col(" my_col" ).add_document({" value" : 1 })
56+ a.{whatever}
57+
58+ # Working with database "my_db"
59+ a.db(" my_db" ).add_collection(" my_col" )
60+ a.db(" my_db" ).col(" my_col" ).add_document({" value" : 1 })
61+ a.db(" my_db" ).{whatever}
4062```
4163
4264## AQL Functions
4365``` python
4466my_db = a.db(" my_db" )
4567
46- # List the AQL functions that's defined in database "my_db"
68+ # List the AQL functions defined in database "my_db"
4769my_db.aql_functions
4870
4971# Add a new AQL function
@@ -52,16 +74,16 @@ my_db.add_aql_function(
5274 " function (celsius) { return celsius * 1.8 + 32; }"
5375)
5476
55- # Remove a AQL function
77+ # Remove an AQL function
5678my_db.remove_aql_function(" myfunctions::temperature::ctof" )
5779```
5880
5981## AQL Queries
6082``` python
61- # Retrieve the execution plan without executing it
83+ # Retrieve the execution plan without actually executing it
6284my_db.explain_query(" FOR doc IN my_col RETURN doc" )
6385
64- # Validate the AQL query without executing it
86+ # Validate the AQL query without actually executing it
6587my_db.validate_query(" FOR doc IN my_col RETURN doc" )
6688
6789# Execute the AQL query and iterate through the AQL cursor
@@ -79,6 +101,9 @@ my_db = a.db("my_db")
79101
80102# List the collection names in "my_db"
81103my_db.collections
104+ my_db.collections[" user" ]
105+ my_db.collecitons[" system" ]
106+ my_db.collections[" all" ]
82107
83108# Add a new collection
84109my_db.add_collection(" new_col" )
@@ -93,7 +118,7 @@ my_db.rename_collection("new_col", "my_col")
93118my_db.remove_collection(" my_col" )
94119
95120# Retrieve collection information
96- my_col = a.db(" my_db" ).collection (" my_col" )
121+ my_col = a.db(" my_db" ).col (" my_col" )
97122len (my_col) == my_col.count
98123my_col.properties
99124my_col.id
@@ -107,6 +132,10 @@ my_col.do_compact
107132my_col.figures
108133my_col.revision
109134
135+ # Modify collection properties (only the modifiable ones)
136+ my_col.wait_for_sync = False
137+ my_col.journal_size = new_journal_size
138+
110139# Load the collection into memory
111140my_col.load()
112141
@@ -117,7 +146,7 @@ my_col.unload()
117146my_col.rotate_journal()
118147
119148# Return the checksum of the collection
120- my_col.checksum()
149+ my_col.checksum(with_rev = True , with_data = True )
121150
122151# Remove all documents in the collection
123152my_col.truncate()
@@ -129,12 +158,12 @@ my_col.contains("a_document_key")
129158
130159## Indexes
131160``` python
132- my_col = a.collection(" my_col" )
161+ my_col = a.collection(" my_col" ) # or a.col("mycol")
133162
134163# List the indexes in collection "my_col"
135164my_col.indexes
136165
137- # Add a unique hash index attributes "attr1" and "attr2"
166+ # Add a unique hash index on attributes "attr1" and "attr2"
138167my_col.add_hash_index(fields = [" attr1" , " attr2" ], unique = True )
139168
140169# Add a cap constraint
@@ -143,7 +172,7 @@ my_col.add_cap_constraint(size=10, byte_size=40000)
143172# Add a unique skiplist index on attributes "attr1" and "attr2"
144173my_col.add_skiplist_index([" attr1" , " attr2" ], unique = True )
145174
146- # Examples of adding a geo-spatial index on 1 or 2 attributes
175+ # Examples of adding a geo-spatial index on 1 ( or 2) coordinate attributes
147176my_col.add_geo_index(fields = [" coordinates" ])
148177my_col.add_geo_index(fields = [" longitude" , " latitude" ])
149178
@@ -185,10 +214,11 @@ my_col.first(5)
185214my_col.last(3 )
186215
187216# Return all documents (cursor generator object)
188- my_col.all()
217+ my_col.all()
218+ list (my_col.all())
189219
190220# Return a random document
191- my_col.any()
221+ my_col.any()
192222
193223# Return first document whose "value" is 1
194224my_col.get_first_example({" value" : 1 })
@@ -198,11 +228,10 @@ my_col.get_by_example({"value": 1})
198228
199229# Update all documents whose "value" is 1 with a new attribute
200230my_col.update_by_example(
201- {" value" : 1 },
202- new_value = {" new_attr" : 1 }
231+ {" value" : 1 }, new_value = {" new_attr" : 1 }
203232)
204233
205- # Return all docs within a radius around a given coordinate (requires geo-index)
234+ # Return all documents within a radius around a given coordinate (requires geo-index)
206235my_col.within(latitude = 100 , longitude = 20 , radius = 15 )
207236
208237# Return all documents near a given coordinate (requires geo-index)
@@ -212,8 +241,10 @@ my_col.near(latitude=100, longitude=20)
212241## Graphs
213242``` python
214243my_db = a.db(" my_db" )
244+
215245# List all the graphs in the database
216- my_db.graphs
246+ my_db.graphs
247+
217248# Add a new graph
218249my_graph = my_db.add_graph(" my_graph" )
219250
@@ -243,7 +274,7 @@ my_graph.orphan_collections
243274
244275## Vertices
245276``` python
246- # Add new vertices
277+ # Add new vertices (again if "_key" is not given it's auto-generated)
247278my_graph.add_vertex(" vcol01" , {" _key" : " v01" , " value" : 1 })
248279my_graph.add_vertex(" vcol02" , {" _key" : " v01" , " value" : 1 })
249280
@@ -261,27 +292,30 @@ my_graph.remove_vertex("vol01/v01")
261292``` python
262293# Add a new edge
263294my_graph.add_edge(
264- " ecol01" ,
295+ " ecol01" , # edge collection name
265296 {
266297 " _key" : " e01" ,
267298 " _from" : " vcol01/v01" , # must abide the edge definition
268299 " _to" : " vcol02/v01" , # must abide the edge definition
269- " value" : 1 ,
300+ " foo" : 1 ,
301+ " bar" : 2 ,
270302 }
271303)
272304
273305# Replace an edge
274- my_graph.replace_edge(" ecol01/e01" , {" new_value " : 2 })
306+ my_graph.replace_edge(" ecol01/e01" , {" baz " : 2 })
275307
276308# Update an edge
277- my_graph.update_edge(" ecol01/e01" , {" value " : 3 })
309+ my_graph.update_edge(" ecol01/e01" , {" foo " : 3 })
278310
279311# Remove an edge
280312my_graph.remove_edge(" ecol01/e01" )
281313```
282314
283315## Graph Traversals
284316``` python
317+ my_graph = a.db(" my_db" ).graph(" my_graph" )
318+
285319# Execute a graph traversal
286320results = my_graph.execute_traversal(
287321 start_vertex = " vcol01/v01" ,
0 commit comments