Skip to content

Commit

Permalink
Add computedValues to collection (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjoubert authored Sep 21, 2022
1 parent 909317b commit fd38882
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions arango/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@ def create_collection(
smart_join_attribute: Optional[str] = None,
write_concern: Optional[int] = None,
schema: Optional[Json] = None,
computedValues: Optional[Jsons] = None,
) -> Result[StandardCollection]:
"""Create a new collection.
Expand Down Expand Up @@ -1010,6 +1011,12 @@ def create_collection(
for documents. See ArangoDB documentation for more information on
document schema validation.
:type schema: dict
:param computedValues: Array of computed values for the new collection
enabling default values to new documents or the maintenance of
auxiliary attributes for search queries. Available in ArangoDB
version 3.10 or greater. See ArangoDB documentation for more
information on computed values.
:type computedValues: list
:return: Standard collection API wrapper.
:rtype: arango.collection.StandardCollection
:raise arango.exceptions.CollectionCreateError: If create fails.
Expand Down Expand Up @@ -1043,6 +1050,8 @@ def create_collection(
data["writeConcern"] = write_concern
if schema is not None:
data["schema"] = schema
if computedValues is not None:
data["computedValues"] = computedValues

params: Params = {}
if sync_replication is not None:
Expand Down
14 changes: 14 additions & 0 deletions arango/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,20 @@ def format_collection(body: Json) -> Json:
if "schema" in body:
result["schema"] = body["schema"]

# New in 3.10
if "computedValues" in body:
result["computedValues"] = [
{
"name": cv["name"],
"expression": cv["expression"],
"overwrite": cv["overwrite"],
"computedOn": cv["computedOn"],
"keepNull": cv["keepNull"],
"failOnWarning": cv["failOnWarning"],
}
for cv in body["computedValues"]
]

return verify_format(body, result)


Expand Down

0 comments on commit fd38882

Please sign in to comment.