From fd3888278b9d6b82b5fe3b1912e80e6e9ce5e548 Mon Sep 17 00:00:00 2001 From: Terence Joubert Date: Thu, 22 Sep 2022 01:39:55 +0400 Subject: [PATCH] Add computedValues to collection (#218) --- arango/database.py | 9 +++++++++ arango/formatter.py | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/arango/database.py b/arango/database.py index 5e9dcfa8..289bfdc9 100644 --- a/arango/database.py +++ b/arango/database.py @@ -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. @@ -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. @@ -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: diff --git a/arango/formatter.py b/arango/formatter.py index adb673cf..ffab8c4b 100644 --- a/arango/formatter.py +++ b/arango/formatter.py @@ -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)