Skip to content

Commit 3d91b98

Browse files
Tariq DaoudaTariq Daouda
authored andcommitted
getitem for docs at db level
1 parent ed464f6 commit 3d91b98

File tree

2 files changed

+80
-53
lines changed

2 files changed

+80
-53
lines changed

pyArango/database.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -526,16 +526,20 @@ def __contains__(self, name_or_id):
526526
else:
527527
return self.hasCollection(name_or_id) or self.hasGraph(name_or_id)
528528

529-
def __getitem__(self, collectionName):
530-
"""use database[collectionName] to get a collection from the database"""
529+
def __getitem__(self, col_or_doc_id):
530+
"""use database[col_or_doc_id] to get a collection from the database"""
531531
try:
532-
return self.collections[collectionName]
533-
except KeyError:
534-
self.reload()
532+
col_name, doc_key = col_or_doc_id.split('/')
533+
return self.collections[col_name][doc_key]
534+
except ValueError:
535535
try:
536-
return self.collections[collectionName]
536+
return self.collections[col_or_doc_id]
537537
except KeyError:
538-
raise KeyError("Can't find any collection named : %s" % collectionName)
538+
self.reload()
539+
try:
540+
return self.collections[col_or_doc_id]
541+
except KeyError:
542+
raise KeyError("Can't find any collection named : %s" % col_or_doc_id)
539543

540544
class DBHandle(Database):
541545
"As the loading of a Database also triggers the loading of collections and graphs within. Only handles are loaded first. The full database are loaded on demand in a fully transparent manner."

0 commit comments

Comments
 (0)