@@ -1578,6 +1578,108 @@ def response_handler(
15781578
15791579 return await self ._executor .execute (request , response_handler )
15801580
1581+ async def import_bulk (
1582+ self ,
1583+ documents : bytes | str ,
1584+ doc_type : Optional [str ] = None ,
1585+ complete : Optional [bool ] = True ,
1586+ details : Optional [bool ] = True ,
1587+ from_prefix : Optional [str ] = None ,
1588+ to_prefix : Optional [str ] = None ,
1589+ overwrite : Optional [bool ] = None ,
1590+ overwrite_collection_prefix : Optional [bool ] = None ,
1591+ on_duplicate : Optional [str ] = None ,
1592+ wait_for_sync : Optional [bool ] = None ,
1593+ ignore_missing : Optional [bool ] = None ,
1594+ ) -> Result [Json ]:
1595+ """Load JSON data in bulk into ArangoDB.
1596+
1597+ Args:
1598+ documents (bytes | str): String representation of the JSON data to import.
1599+ doc_type (str | None): Determines how the body of the request is interpreted.
1600+ Possible values: "", "documents", "array", "auto".
1601+ complete (bool | None): If set to `True`, the whole import fails if any error occurs.
1602+ Otherwise, the import continues even if some documents are invalid and cannot
1603+ be imported, skipping the problematic documents.
1604+ details (bool | None): If set to `True`, the result includes a `details`
1605+ attribute with information about documents that could not be imported.
1606+ from_prefix (str | None): String prefix prepended to the value of "_from"
1607+ field in each edge document inserted. For example, prefix "foo"
1608+ prepended to "_from": "bar" will result in "_from": "foo/bar".
1609+ Applies only to edge collections.
1610+ to_prefix (str | None): String prefix prepended to the value of "_to"
1611+ field in each edge document inserted. For example, prefix "foo"
1612+ prepended to "_to": "bar" will result in "_to": "foo/bar".
1613+ Applies only to edge collections.
1614+ overwrite (bool | None): If set to `True`, all existing documents are removed
1615+ prior to the import. Indexes are still preserved.
1616+ overwrite_collection_prefix (bool | None): Force the `fromPrefix` and
1617+ `toPrefix`, possibly replacing existing collection name prefixes.
1618+ on_duplicate (str | None): Action to take on unique key constraint violations
1619+ (for documents with "_key" fields). Allowed values are "error" (do
1620+ not import the new documents and count them as errors), "update"
1621+ (update the existing documents while preserving any fields missing
1622+ in the new ones), "replace" (replace the existing documents with
1623+ new ones), and "ignore" (do not import the new documents and count
1624+ them as ignored, as opposed to counting them as errors). Options
1625+ "update" and "replace" may fail on secondary unique key constraint
1626+ violations.
1627+ wait_for_sync (bool | None): Block until operation is synchronized to disk.
1628+ ignore_missing (bool | None): When importing JSON arrays of tabular data
1629+ (type parameter is omitted), the first line of the request body defines
1630+ the attribute keys and the subsequent lines the attribute values for each
1631+ document. Subsequent lines with a different number of elements than the
1632+ first line are not imported by default. You can enable this option to
1633+ import them anyway. For the missing elements, the document attributes
1634+ are omitted. Excess elements are ignored.
1635+
1636+ Returns:
1637+ dict: Result of the import operation.
1638+
1639+ Raises:
1640+ DocumentInsertError: If import fails.
1641+
1642+ References:
1643+ - `import-json-data-as-documents <https://docs.arangodb.com/stable/develop/http-api/import/#import-json-data-as-documents>`__
1644+ """ # noqa: E501
1645+ params : Params = dict ()
1646+ params ["collection" ] = self .name
1647+ if doc_type is not None :
1648+ params ["type" ] = doc_type
1649+ if complete is not None :
1650+ params ["complete" ] = complete
1651+ if details is not None :
1652+ params ["details" ] = details
1653+ if from_prefix is not None :
1654+ params ["fromPrefix" ] = from_prefix
1655+ if to_prefix is not None :
1656+ params ["toPrefix" ] = to_prefix
1657+ if overwrite is not None :
1658+ params ["overwrite" ] = overwrite
1659+ if overwrite_collection_prefix is not None :
1660+ params ["overwriteCollectionPrefix" ] = overwrite_collection_prefix
1661+ if on_duplicate is not None :
1662+ params ["onDuplicate" ] = on_duplicate
1663+ if wait_for_sync is not None :
1664+ params ["waitForSync" ] = wait_for_sync
1665+ if ignore_missing is not None :
1666+ params ["ignoreMissing" ] = ignore_missing
1667+
1668+ def response_handler (resp : Response ) -> Json :
1669+ if not resp .is_success :
1670+ raise DocumentInsertError (resp , request )
1671+ result : Json = self .deserializer .loads (resp .raw_body )
1672+ return result
1673+
1674+ request = Request (
1675+ method = Method .POST ,
1676+ endpoint = "/_api/import" ,
1677+ data = documents ,
1678+ params = params ,
1679+ )
1680+
1681+ return await self ._executor .execute (request , response_handler )
1682+
15811683
15821684class StandardCollection (Collection [T , U , V ]):
15831685 """Standard collection API wrapper.
0 commit comments