|
46 | 46 | UserListError,
|
47 | 47 | UserReplaceError,
|
48 | 48 | UserUpdateError,
|
| 49 | + ViewCreateError, |
| 50 | + ViewDeleteError, |
| 51 | + ViewGetError, |
| 52 | + ViewListError, |
| 53 | + ViewRenameError, |
| 54 | + ViewReplaceError, |
| 55 | + ViewUpdateError, |
49 | 56 | )
|
50 | 57 | from arangoasync.executor import (
|
51 | 58 | ApiExecutor,
|
@@ -1223,6 +1230,237 @@ def response_handler(resp: Response) -> bool:
|
1223 | 1230 |
|
1224 | 1231 | return await self._executor.execute(request, response_handler)
|
1225 | 1232 |
|
| 1233 | + async def view(self, name: str) -> Result[Json]: |
| 1234 | + """Return the properties of a view. |
| 1235 | +
|
| 1236 | + Args: |
| 1237 | + name (str): View name. |
| 1238 | +
|
| 1239 | + Returns: |
| 1240 | + dict: View properties. |
| 1241 | +
|
| 1242 | + Raises: |
| 1243 | + ViewGetError: If the operation fails. |
| 1244 | +
|
| 1245 | + References: |
| 1246 | + - `read-properties-of-a-view <https://docs.arangodb.com/stable/develop/http-api/views/search-alias-views/#read-properties-of-a-view>`__ |
| 1247 | + - `get-the-properties-of-a-view <https://docs.arangodb.com/stable/develop/http-api/views/arangosearch-views/#get-the-properties-of-a-view>`__ |
| 1248 | + """ # noqa: E501 |
| 1249 | + request = Request(method=Method.GET, endpoint=f"/_api/view/{name}/properties") |
| 1250 | + |
| 1251 | + def response_handler(resp: Response) -> Json: |
| 1252 | + if not resp.is_success: |
| 1253 | + raise ViewGetError(resp, request) |
| 1254 | + return self.deserializer.loads(resp.raw_body) |
| 1255 | + |
| 1256 | + return await self._executor.execute(request, response_handler) |
| 1257 | + |
| 1258 | + async def view_info(self, name: str) -> Result[Json]: |
| 1259 | + """Return basic information about a specific view. |
| 1260 | +
|
| 1261 | + Args: |
| 1262 | + name (str): View name. |
| 1263 | +
|
| 1264 | + Returns: |
| 1265 | + dict: View information. |
| 1266 | +
|
| 1267 | + Raises: |
| 1268 | + ViewGetError: If the operation fails. |
| 1269 | +
|
| 1270 | + References: |
| 1271 | + - `get-information-about-a-view <https://docs.arangodb.com/stable/develop/http-api/views/search-alias-views/#get-information-about-a-view>`_ |
| 1272 | + - `get-information-about-a-view <https://docs.arangodb.com/stable/develop/http-api/views/arangosearch-views/#get-information-about-a-view>`__ |
| 1273 | + """ # noqa: E501 |
| 1274 | + request = Request(method=Method.GET, endpoint=f"/_api/view/{name}") |
| 1275 | + |
| 1276 | + def response_handler(resp: Response) -> Json: |
| 1277 | + if not resp.is_success: |
| 1278 | + raise ViewGetError(resp, request) |
| 1279 | + return self.deserializer.loads(resp.raw_body) |
| 1280 | + |
| 1281 | + return await self._executor.execute(request, response_handler) |
| 1282 | + |
| 1283 | + async def views(self) -> Result[Jsons]: |
| 1284 | + """List all views in the database along with their summary information. |
| 1285 | +
|
| 1286 | + Returns: |
| 1287 | + list: List of views with their properties. |
| 1288 | +
|
| 1289 | + Raises: |
| 1290 | + ViewListError: If the operation fails. |
| 1291 | +
|
| 1292 | + References: |
| 1293 | + - `list-all-views <https://docs.arangodb.com/stable/develop/http-api/views/search-alias-views/#list-all-views>`__ |
| 1294 | + - `list-all-views <https://docs.arangodb.com/stable/develop/http-api/views/arangosearch-views/#list-all-views>`__ |
| 1295 | + """ # noqa: E501 |
| 1296 | + request = Request(method=Method.GET, endpoint="/_api/view") |
| 1297 | + |
| 1298 | + def response_handler(resp: Response) -> Jsons: |
| 1299 | + if not resp.is_success: |
| 1300 | + raise ViewListError(resp, request) |
| 1301 | + body = self.deserializer.loads(resp.raw_body) |
| 1302 | + return cast(Jsons, body["result"]) |
| 1303 | + |
| 1304 | + return await self._executor.execute(request, response_handler) |
| 1305 | + |
| 1306 | + async def create_view( |
| 1307 | + self, |
| 1308 | + name: str, |
| 1309 | + view_type: str, |
| 1310 | + properties: Optional[Json] = None, |
| 1311 | + ) -> Result[Json]: |
| 1312 | + """Create a view. |
| 1313 | +
|
| 1314 | + Args: |
| 1315 | + name (str): View name. |
| 1316 | + view_type (str): Type of the view (e.g., "arangosearch", "view"). |
| 1317 | + properties (dict | None): Properties of the view. |
| 1318 | +
|
| 1319 | + Returns: |
| 1320 | + dict: View properties. |
| 1321 | +
|
| 1322 | + Raises: |
| 1323 | + ViewCreateError: If the operation fails. |
| 1324 | +
|
| 1325 | + References: |
| 1326 | + - `create-a-search-alias-view <https://docs.arangodb.com/stable/develop/http-api/views/search-alias-views/#create-a-search-alias-view>`__ |
| 1327 | + - `create-an-arangosearch-view <https://docs.arangodb.com/stable/develop/http-api/views/arangosearch-views/#create-an-arangosearch-view>`__ |
| 1328 | + """ # noqa: E501 |
| 1329 | + data: Json = {"name": name, "type": view_type} |
| 1330 | + if properties is not None: |
| 1331 | + data.update(properties) |
| 1332 | + |
| 1333 | + request = Request( |
| 1334 | + method=Method.POST, |
| 1335 | + endpoint="/_api/view", |
| 1336 | + data=self.serializer.dumps(data), |
| 1337 | + ) |
| 1338 | + |
| 1339 | + def response_handler(resp: Response) -> Json: |
| 1340 | + if not resp.is_success: |
| 1341 | + raise ViewCreateError(resp, request) |
| 1342 | + return self.deserializer.loads(resp.raw_body) |
| 1343 | + |
| 1344 | + return await self._executor.execute(request, response_handler) |
| 1345 | + |
| 1346 | + async def replace_view(self, name: str, properties: Json) -> Result[Json]: |
| 1347 | + """Replace the properties of an existing view. |
| 1348 | +
|
| 1349 | + Args: |
| 1350 | + name (str): View name. |
| 1351 | + properties (dict): New properties for the view. |
| 1352 | +
|
| 1353 | + Returns: |
| 1354 | + dict: Updated view properties. |
| 1355 | +
|
| 1356 | + Raises: |
| 1357 | + ViewReplaceError: If the operation fails. |
| 1358 | +
|
| 1359 | + References: |
| 1360 | + - `replace-the-properties-of-a-search-alias-view <https://docs.arangodb.com/stable/develop/http-api/views/search-alias-views/#replace-the-properties-of-a-search-alias-view>`__ |
| 1361 | + - `replace-the-properties-of-an-arangosearch-view <https://docs.arangodb.com/stable/develop/http-api/views/arangosearch-views/#replace-the-properties-of-an-arangosearch-view>`__ |
| 1362 | + """ # noqa: E501 |
| 1363 | + request = Request( |
| 1364 | + method=Method.PUT, |
| 1365 | + endpoint=f"/_api/view/{name}/properties", |
| 1366 | + data=self.serializer.dumps(properties), |
| 1367 | + ) |
| 1368 | + |
| 1369 | + def response_handler(resp: Response) -> Json: |
| 1370 | + if resp.is_success: |
| 1371 | + return self.deserializer.loads(resp.raw_body) |
| 1372 | + raise ViewReplaceError(resp, request) |
| 1373 | + |
| 1374 | + return await self._executor.execute(request, response_handler) |
| 1375 | + |
| 1376 | + async def update_view(self, name: str, properties: Json) -> Result[Json]: |
| 1377 | + """Update the properties of an existing view. |
| 1378 | +
|
| 1379 | + Args: |
| 1380 | + name (str): View name. |
| 1381 | + properties (dict): New properties for the view. |
| 1382 | +
|
| 1383 | + Returns: |
| 1384 | + dict: Updated view properties. |
| 1385 | +
|
| 1386 | + Raises: |
| 1387 | + ViewUpdateError: If the operation fails. |
| 1388 | +
|
| 1389 | + References: |
| 1390 | + - `update-the-properties-of-a-search-alias-view <https://docs.arangodb.com/stable/develop/http-api/views/search-alias-views/#update-the-properties-of-a-search-alias-view>`__ |
| 1391 | + - `update-the-properties-of-an-arangosearch-view <https://docs.arangodb.com/stable/develop/http-api/views/arangosearch-views/#update-the-properties-of-an-arangosearch-view>`__ |
| 1392 | + """ # noqa: E501 |
| 1393 | + request = Request( |
| 1394 | + method=Method.PATCH, |
| 1395 | + endpoint=f"/_api/view/{name}/properties", |
| 1396 | + data=self.serializer.dumps(properties), |
| 1397 | + ) |
| 1398 | + |
| 1399 | + def response_handler(resp: Response) -> Json: |
| 1400 | + if resp.is_success: |
| 1401 | + return self.deserializer.loads(resp.raw_body) |
| 1402 | + raise ViewUpdateError(resp, request) |
| 1403 | + |
| 1404 | + return await self._executor.execute(request, response_handler) |
| 1405 | + |
| 1406 | + async def rename_view(self, name: str, new_name: str) -> None: |
| 1407 | + """Rename an existing view (not supported in cluster deployments). |
| 1408 | +
|
| 1409 | + Args: |
| 1410 | + name (str): Current view name. |
| 1411 | + new_name (str): New view name. |
| 1412 | +
|
| 1413 | + Raises: |
| 1414 | + ViewRenameError: If the operation fails. |
| 1415 | +
|
| 1416 | + References: |
| 1417 | + - `rename-a-view <https://docs.arangodb.com/stable/develop/http-api/views/search-alias-views/#rename-a-view>`__ |
| 1418 | + - `rename-a-view <https://docs.arangodb.com/stable/develop/http-api/views/arangosearch-views/#rename-a-view>`__ |
| 1419 | + """ # noqa: E501 |
| 1420 | + request = Request( |
| 1421 | + method=Method.PUT, |
| 1422 | + endpoint=f"/_api/view/{name}/rename", |
| 1423 | + data=self.serializer.dumps({"name": new_name}), |
| 1424 | + ) |
| 1425 | + |
| 1426 | + def response_handler(resp: Response) -> None: |
| 1427 | + if not resp.is_success: |
| 1428 | + raise ViewRenameError(resp, request) |
| 1429 | + |
| 1430 | + await self._executor.execute(request, response_handler) |
| 1431 | + |
| 1432 | + async def delete_view( |
| 1433 | + self, name: str, ignore_missing: bool = False |
| 1434 | + ) -> Result[bool]: |
| 1435 | + """Delete a view. |
| 1436 | +
|
| 1437 | + Args: |
| 1438 | + name (str): View name. |
| 1439 | + ignore_missing (bool): If `True`, do not raise an exception if the |
| 1440 | + view does not exist. |
| 1441 | +
|
| 1442 | + Returns: |
| 1443 | + bool: `True` if the view was deleted successfully, `False` if the |
| 1444 | + view was not found and **ignore_missing** was set to `True`. |
| 1445 | +
|
| 1446 | + Raises: |
| 1447 | + ViewDeleteError: If the operation fails. |
| 1448 | +
|
| 1449 | + References: |
| 1450 | + - `drop-a-view <https://docs.arangodb.com/stable/develop/http-api/views/search-alias-views/#drop-a-view>`__ |
| 1451 | + - `drop-a-view <https://docs.arangodb.com/stable/develop/http-api/views/arangosearch-views/#drop-a-view>`__ |
| 1452 | + """ # noqa: E501 |
| 1453 | + request = Request(method=Method.DELETE, endpoint=f"/_api/view/{name}") |
| 1454 | + |
| 1455 | + def response_handler(resp: Response) -> bool: |
| 1456 | + if resp.is_success: |
| 1457 | + return True |
| 1458 | + if resp.status_code == HTTP_NOT_FOUND and ignore_missing: |
| 1459 | + return False |
| 1460 | + raise ViewDeleteError(resp, request) |
| 1461 | + |
| 1462 | + return await self._executor.execute(request, response_handler) |
| 1463 | + |
1226 | 1464 | async def has_user(self, username: str) -> Result[bool]:
|
1227 | 1465 | """Check if a user exists.
|
1228 | 1466 |
|
|
0 commit comments