Skip to content

Commit d4c0fc6

Browse files
committed
Updating docs
1 parent b699213 commit d4c0fc6

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

docs/document.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,54 @@ Standard documents are managed via collection API wrapper:
150150
# Delete one or more matching documents.
151151
await students.delete_match({"first": "Emma"})
152152
153+
You can manage documents via database API wrappers also, but only simple
154+
operations (i.e. get, insert, update, replace, delete) are supported and you
155+
must provide document IDs instead of keys:
156+
157+
.. code-block:: python
158+
159+
from arangoasync import ArangoClient
160+
from arangoasync.auth import Auth
161+
162+
# Initialize the client for ArangoDB.
163+
async with ArangoClient(hosts="http://localhost:8529") as client:
164+
auth = Auth(username="root", password="passwd")
165+
166+
# Connect to "test" database as root user.
167+
db = await client.db("test", auth=auth)
168+
169+
# Create a new collection named "students" if it does not exist.
170+
if not await db.has_collection("students"):
171+
await db.create_collection("students")
172+
173+
# Create some test documents to play around with.
174+
# The documents must have the "_id" field instead.
175+
lola = {"_id": "students/lola", "GPA": 3.5}
176+
abby = {"_id": "students/abby", "GPA": 3.2}
177+
john = {"_id": "students/john", "GPA": 3.6}
178+
emma = {"_id": "students/emma", "GPA": 4.0}
179+
180+
# Insert a new document.
181+
metadata = await db.insert_document("students", lola)
182+
assert metadata["_id"] == "students/lola"
183+
assert metadata["_key"] == "lola"
184+
185+
# Check if a document exists.
186+
assert await db.has_document(lola) is True
187+
188+
# Get a document (by ID or body with "_id" field).
189+
await db.document("students/lola")
190+
await db.document(abby)
191+
192+
# Update a document.
193+
lola["GPA"] = 3.6
194+
await db.update_document(lola)
195+
196+
# Replace a document.
197+
lola["GPA"] = 3.4
198+
await db.replace_document(lola)
199+
200+
# Delete a document (by ID or body with "_id" field).
201+
await db.delete_document("students/lola")
202+
153203
See :class:`arangoasync.database.StandardDatabase` and :class:`arangoasync.collection.StandardCollection` for API specification.

0 commit comments

Comments
 (0)