Skip to content

Commit 434f311

Browse files
committed
Added computedValues property to collection
1 parent 6da57e0 commit 434f311

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

arango/database.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,7 @@ def create_collection(
933933
smart_join_attribute: Optional[str] = None,
934934
write_concern: Optional[int] = None,
935935
schema: Optional[Json] = None,
936+
computedValues: Optional[Jsons] = None,
936937
) -> Result[StandardCollection]:
937938
"""Create a new collection.
938939
@@ -1010,6 +1011,12 @@ def create_collection(
10101011
for documents. See ArangoDB documentation for more information on
10111012
document schema validation.
10121013
:type schema: dict
1014+
:param computedValues: Array of computed values for the new collection
1015+
enabling default values to new documents or the maintenance of
1016+
auxiliary attributes for search queries. Available in ArangoDB
1017+
version 3.10 or greater. See ArangoDB documentation for more
1018+
information on computed values.
1019+
:type computedValues: list
10131020
:return: Standard collection API wrapper.
10141021
:rtype: arango.collection.StandardCollection
10151022
:raise arango.exceptions.CollectionCreateError: If create fails.
@@ -1043,6 +1050,8 @@ def create_collection(
10431050
data["writeConcern"] = write_concern
10441051
if schema is not None:
10451052
data["schema"] = schema
1053+
if computedValues is not None:
1054+
data["computedValues"] = computedValues
10461055

10471056
params: Params = {}
10481057
if sync_replication is not None:

arango/formatter.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any
22

3-
from arango.typings import Headers, Json
3+
from arango.typings import Headers, Json, Jsons
44

55

66
def verify_format(_: Any, res: Json) -> Json:
@@ -208,6 +208,52 @@ def format_collection(body: Json) -> Json:
208208
if "schema" in body:
209209
result["schema"] = body["schema"]
210210

211+
# New in 3.10
212+
if "computedValues" in body:
213+
result["computedValues"] = format_collection_computed_values(body["computedValues"])
214+
215+
return verify_format(body, result)
216+
217+
218+
def format_collection_computed_values(body: Jsons) -> Jsons:
219+
"""Format collection computed values data.
220+
221+
:param body: Input body.
222+
:type body: dict
223+
:return: Formatted body.
224+
:rtype: dict
225+
"""
226+
result: Jsons = []
227+
228+
for item in body:
229+
result.append(format_collection_computed_value_item(item))
230+
231+
return verify_format(body, result)
232+
233+
234+
def format_collection_computed_value_item(body: Json) -> Json:
235+
"""Format a computed value item for a collection.
236+
237+
:param body: Input body.
238+
:type body: dict
239+
:return: Formatted body.
240+
:rtype: dict
241+
"""
242+
result: Json = {}
243+
244+
if "name" in body:
245+
result["name"] = body["name"]
246+
if "expression" in body:
247+
result["expression"] = body["expression"]
248+
if "overwrite" in body:
249+
result["overwrite"] = body["overwrite"]
250+
if "computedOn" in body:
251+
result["computedOn"] = body["computedOn"]
252+
if "keepNull" in body:
253+
result["keepNull"] = body["keepNull"]
254+
if "failOnWarning" in body:
255+
result["failOnWarning"] = body["failOnWarning"]
256+
211257
return verify_format(body, result)
212258

213259

0 commit comments

Comments
 (0)