2
2
3
3
from numbers import Number
4
4
from typing import List , Optional , Sequence , Tuple , Union
5
+ from warnings import warn
5
6
6
7
from arango .api import ApiGroup
7
8
from arango .connection import Connection
@@ -1074,7 +1075,7 @@ def build_coord_str_from_index(index: Json) -> str:
1074
1075
FILTER GEO_CONTAINS(rect, { coord_str } )
1075
1076
LIMIT { skip_val } , { limit_val }
1076
1077
RETURN doc
1077
- """
1078
+ """ # noqa: E201 E202
1078
1079
1079
1080
bind_vars = {"@collection" : self .name }
1080
1081
@@ -1259,11 +1260,27 @@ def response_handler(resp: Response) -> Json:
1259
1260
1260
1261
return self ._execute (request , response_handler )
1261
1262
1262
- def _add_index (self , data : Json ) -> Result [Json ]:
1263
- """Helper method for creating a new index.
1263
+ def add_index (self , data : Json , formatter : bool = False ) -> Result [Json ]:
1264
+ """Create an index.
1265
+
1266
+ .. note::
1264
1267
1265
- :param data: Index data.
1268
+ As the `add_index` method was made available starting with driver
1269
+ version 8, we have decided to deprecate the other `add_*_index`
1270
+ methods, making this the official way to create indexes. While
1271
+ the other methods still work, we recommend using this one instead.
1272
+ Note that the other methods would use a formatter by default,
1273
+ processing the index attributes returned by the server (for the
1274
+ most part, it does a snake case conversion). This method skips that,
1275
+ returning the raw index, except for the `id` attribute. However,
1276
+ if you want the formatter to be applied for backwards compatibility,
1277
+ you can set the `formatter` parameter to `True`.
1278
+
1279
+ :param data: Index data. Must contain a "type" and "fields" attribute.
1266
1280
:type data: dict
1281
+ :param formatter: If set to True, apply formatting to the returned result.
1282
+ Should only be used for backwards compatibility.
1283
+ :type formatter: bool
1267
1284
:return: New index details.
1268
1285
:rtype: dict
1269
1286
:raise arango.exceptions.IndexCreateError: If create fails.
@@ -1278,7 +1295,7 @@ def _add_index(self, data: Json) -> Result[Json]:
1278
1295
def response_handler (resp : Response ) -> Json :
1279
1296
if not resp .is_success :
1280
1297
raise IndexCreateError (resp , request )
1281
- return format_index (resp .body )
1298
+ return format_index (resp .body , formatter )
1282
1299
1283
1300
return self ._execute (request , response_handler )
1284
1301
@@ -1297,8 +1314,7 @@ def add_hash_index(
1297
1314
1298
1315
The index types `hash` and `skiplist` are aliases for the persistent
1299
1316
index type and should no longer be used to create new indexes. The
1300
- aliases will be removed in a future version. Use
1301
- :func:`arango.collection.Collection.add_persistent_index` instead.
1317
+ aliases will be removed in a future version.
1302
1318
1303
1319
:param fields: Document fields to index.
1304
1320
:type fields: [str]
@@ -1318,6 +1334,9 @@ def add_hash_index(
1318
1334
:rtype: dict
1319
1335
:raise arango.exceptions.IndexCreateError: If create fails.
1320
1336
"""
1337
+ m = "add_hash_index is deprecated. Using add_index with {'type': 'hash'} instead." # noqa: E501
1338
+ warn (m , DeprecationWarning , stacklevel = 2 )
1339
+
1321
1340
data : Json = {"type" : "hash" , "fields" : fields }
1322
1341
1323
1342
if unique is not None :
@@ -1331,7 +1350,7 @@ def add_hash_index(
1331
1350
if in_background is not None :
1332
1351
data ["inBackground" ] = in_background
1333
1352
1334
- return self ._add_index (data )
1353
+ return self .add_index (data , formatter = True )
1335
1354
1336
1355
def add_skiplist_index (
1337
1356
self ,
@@ -1348,8 +1367,7 @@ def add_skiplist_index(
1348
1367
1349
1368
The index types `hash` and `skiplist` are aliases for the persistent
1350
1369
index type and should no longer be used to create new indexes. The
1351
- aliases will be removed in a future version. Use
1352
- :func:`arango.collection.Collection.add_persistent_index` instead.
1370
+ aliases will be removed in a future version.
1353
1371
1354
1372
:param fields: Document fields to index.
1355
1373
:type fields: [str]
@@ -1369,6 +1387,9 @@ def add_skiplist_index(
1369
1387
:rtype: dict
1370
1388
:raise arango.exceptions.IndexCreateError: If create fails.
1371
1389
"""
1390
+ m = "add_skiplist_index is deprecated. Using add_index with {'type': 'skiplist'} instead." # noqa: E501
1391
+ warn (m , DeprecationWarning , stacklevel = 2 )
1392
+
1372
1393
data : Json = {"type" : "skiplist" , "fields" : fields }
1373
1394
1374
1395
if unique is not None :
@@ -1382,7 +1403,7 @@ def add_skiplist_index(
1382
1403
if in_background is not None :
1383
1404
data ["inBackground" ] = in_background
1384
1405
1385
- return self ._add_index (data )
1406
+ return self .add_index (data , formatter = True )
1386
1407
1387
1408
def add_geo_index (
1388
1409
self ,
@@ -1414,6 +1435,9 @@ def add_geo_index(
1414
1435
:rtype: dict
1415
1436
:raise arango.exceptions.IndexCreateError: If create fails.
1416
1437
"""
1438
+ m = "add_geo_index is deprecated. Using add_index with {'type': 'geo'} instead." # noqa: E501
1439
+ warn (m , DeprecationWarning , stacklevel = 2 )
1440
+
1417
1441
data : Json = {"type" : "geo" , "fields" : fields }
1418
1442
1419
1443
if geo_json is not None :
@@ -1425,7 +1449,7 @@ def add_geo_index(
1425
1449
if legacyPolygons is not None :
1426
1450
data ["legacyPolygons" ] = legacyPolygons
1427
1451
1428
- return self ._add_index (data )
1452
+ return self .add_index (data , formatter = True )
1429
1453
1430
1454
def add_fulltext_index (
1431
1455
self ,
@@ -1434,9 +1458,11 @@ def add_fulltext_index(
1434
1458
name : Optional [str ] = None ,
1435
1459
in_background : Optional [bool ] = None ,
1436
1460
) -> Result [Json ]:
1437
- """Create a new fulltext index. This method is deprecated
1438
- in ArangoDB 3.10 and will be removed in a future version
1439
- of the driver.
1461
+ """Create a new fulltext index.
1462
+
1463
+ .. warning::
1464
+ This method is deprecated since ArangoDB 3.10 and will be removed
1465
+ in a future version of the driver.
1440
1466
1441
1467
:param fields: Document fields to index.
1442
1468
:type fields: [str]
@@ -1450,6 +1476,9 @@ def add_fulltext_index(
1450
1476
:rtype: dict
1451
1477
:raise arango.exceptions.IndexCreateError: If create fails.
1452
1478
"""
1479
+ m = "add_fulltext_index is deprecated. Using add_index with {'type': 'fulltext'} instead." # noqa: E501
1480
+ warn (m , DeprecationWarning , stacklevel = 2 )
1481
+
1453
1482
data : Json = {"type" : "fulltext" , "fields" : fields }
1454
1483
1455
1484
if min_length is not None :
@@ -1459,7 +1488,7 @@ def add_fulltext_index(
1459
1488
if in_background is not None :
1460
1489
data ["inBackground" ] = in_background
1461
1490
1462
- return self ._add_index (data )
1491
+ return self .add_index (data , formatter = True )
1463
1492
1464
1493
def add_persistent_index (
1465
1494
self ,
@@ -1502,6 +1531,9 @@ def add_persistent_index(
1502
1531
:rtype: dict
1503
1532
:raise arango.exceptions.IndexCreateError: If create fails.
1504
1533
"""
1534
+ m = "add_persistent_index is deprecated. Using add_index with {'type': 'persistent'} instead." # noqa: E501
1535
+ warn (m , DeprecationWarning , stacklevel = 2 )
1536
+
1505
1537
data : Json = {"type" : "persistent" , "fields" : fields }
1506
1538
1507
1539
if unique is not None :
@@ -1517,7 +1549,7 @@ def add_persistent_index(
1517
1549
if cacheEnabled is not None :
1518
1550
data ["cacheEnabled" ] = cacheEnabled
1519
1551
1520
- return self ._add_index (data )
1552
+ return self .add_index (data , formatter = True )
1521
1553
1522
1554
def add_ttl_index (
1523
1555
self ,
@@ -1540,14 +1572,17 @@ def add_ttl_index(
1540
1572
:rtype: dict
1541
1573
:raise arango.exceptions.IndexCreateError: If create fails.
1542
1574
"""
1575
+ m = "add_ttl_index is deprecated. Using add_index with {'type': 'ttl'} instead." # noqa: E501
1576
+ warn (m , DeprecationWarning , stacklevel = 2 )
1577
+
1543
1578
data : Json = {"type" : "ttl" , "fields" : fields , "expireAfter" : expiry_time }
1544
1579
1545
1580
if name is not None :
1546
1581
data ["name" ] = name
1547
1582
if in_background is not None :
1548
1583
data ["inBackground" ] = in_background
1549
1584
1550
- return self ._add_index (data )
1585
+ return self .add_index (data , formatter = True )
1551
1586
1552
1587
def add_inverted_index (
1553
1588
self ,
@@ -1602,6 +1637,9 @@ def add_inverted_index(
1602
1637
:rtype: dict
1603
1638
:raise arango.exceptions.IndexCreateError: If create fails.
1604
1639
"""
1640
+ m = "add_inverted_index is deprecated. Using add_index with {'type': 'inverted'} instead." # noqa: E501
1641
+ warn (m , DeprecationWarning , stacklevel = 2 )
1642
+
1605
1643
data : Json = {"type" : "inverted" , "fields" : fields }
1606
1644
1607
1645
if name is not None :
@@ -1631,90 +1669,7 @@ def add_inverted_index(
1631
1669
if cache is not None :
1632
1670
data ["cache" ] = cache
1633
1671
1634
- return self ._add_index (data )
1635
-
1636
- def add_zkd_index (
1637
- self ,
1638
- fields : Sequence [str ],
1639
- field_value_types : str = "double" ,
1640
- name : Optional [str ] = None ,
1641
- unique : Optional [bool ] = None ,
1642
- in_background : Optional [bool ] = None ,
1643
- ) -> Result [Json ]:
1644
- """Create a new ZKD Index.
1645
-
1646
- :param fields: Document fields to index. Unlike for other indexes the
1647
- order of the fields does not matter.
1648
- :type fields: Sequence[str]
1649
- :param field_value_types: The type of the field values. The only allowed
1650
- value is "double" at the moment. Defaults to "double".
1651
- :type field_value_types: str
1652
- :param name: Optional name for the index.
1653
- :type name: str | None
1654
- :param unique: Whether the index is unique.
1655
- :type unique: bool | None
1656
- :param in_background: Do not hold the collection lock.
1657
- :type in_background: bool | None
1658
- :return: New index details.
1659
- :rtype: dict
1660
- :raise arango.exceptions.IndexCreateError: If create fails.
1661
- """
1662
- data : Json = {
1663
- "type" : "zkd" ,
1664
- "fields" : fields ,
1665
- "fieldValueTypes" : field_value_types ,
1666
- }
1667
-
1668
- if unique is not None :
1669
- data ["unique" ] = unique
1670
- if name is not None :
1671
- data ["name" ] = name
1672
- if in_background is not None :
1673
- data ["inBackground" ] = in_background
1674
-
1675
- return self ._add_index (data )
1676
-
1677
- def add_mdi_index (
1678
- self ,
1679
- fields : Sequence [str ],
1680
- field_value_types : str = "double" ,
1681
- name : Optional [str ] = None ,
1682
- unique : Optional [bool ] = None ,
1683
- in_background : Optional [bool ] = None ,
1684
- ) -> Result [Json ]:
1685
- """Create a new MDI index, previously known as ZKD index. This method
1686
- is only usable with ArangoDB 3.12 and later.
1687
-
1688
- :param fields: Document fields to index. Unlike for other indexes the
1689
- order of the fields does not matter.
1690
- :type fields: Sequence[str]
1691
- :param field_value_types: The type of the field values. The only allowed
1692
- value is "double" at the moment. Defaults to "double".
1693
- :type field_value_types: str
1694
- :param name: Optional name for the index.
1695
- :type name: str | None
1696
- :param unique: Whether the index is unique.
1697
- :type unique: bool | None
1698
- :param in_background: Do not hold the collection lock.
1699
- :type in_background: bool | None
1700
- :return: New index details.
1701
- :rtype: dict
1702
- :raise arango.exceptions.IndexCreateError: If create fails.
1703
- """
1704
- data : Json = {
1705
- "type" : "mdi" ,
1706
- "fields" : fields ,
1707
- "fieldValueTypes" : field_value_types ,
1708
- }
1709
-
1710
- if unique is not None :
1711
- data ["unique" ] = unique
1712
- if name is not None :
1713
- data ["name" ] = name
1714
- if in_background is not None :
1715
- data ["inBackground" ] = in_background
1716
-
1717
- return self ._add_index (data )
1672
+ return self .add_index (data , formatter = True )
1718
1673
1719
1674
def delete_index (self , index_id : str , ignore_missing : bool = False ) -> Result [bool ]:
1720
1675
"""Delete an index.
@@ -2076,7 +2031,7 @@ def update_match(
2076
2031
{ f"LIMIT { limit } " if limit is not None else "" }
2077
2032
UPDATE doc WITH @body IN @@collection
2078
2033
OPTIONS {{ keepNull: @keep_none, mergeObjects: @merge { sync_val } }}
2079
- """
2034
+ """ # noqa: E201 E202
2080
2035
2081
2036
bind_vars = {
2082
2037
"@collection" : self .name ,
@@ -2261,7 +2216,7 @@ def replace_match(
2261
2216
{ f"LIMIT { limit } " if limit is not None else "" }
2262
2217
REPLACE doc WITH @body IN @@collection
2263
2218
{ f"OPTIONS {{ { sync_val } }}" if sync_val else "" }
2264
- """
2219
+ """ # noqa: E201 E202
2265
2220
2266
2221
bind_vars = {"@collection" : self .name , "body" : body }
2267
2222
@@ -2426,7 +2381,7 @@ def delete_match(
2426
2381
{ f"LIMIT { limit } " if limit is not None else "" }
2427
2382
REMOVE doc IN @@collection
2428
2383
{ f"OPTIONS {{ { sync_val } }}" if sync_val else "" }
2429
- """
2384
+ """ # noqa: E201 E202
2430
2385
2431
2386
bind_vars = {"@collection" : self .name }
2432
2387
0 commit comments