diff --git a/nocodb/api.py b/nocodb/api.py index 296fa21..b0fffdc 100644 --- a/nocodb/api.py +++ b/nocodb/api.py @@ -1,4 +1,5 @@ from enum import Enum +from typing import Optional from urllib.parse import urljoin from .nocodb import NocoDBProject @@ -50,6 +51,27 @@ def get_row_detail_uri( ) )) + def get_row_relation_create_uri( + self, + project: NocoDBProject, + table: str, + relation_type: str, + row_id: int, + column_name: str, + ref_row_id: int, + ) -> str: + return urljoin(self.__base_data_uri, "/".join( + ( + project.org_name, + project.project_name, + table, + str(row_id), + relation_type, + column_name, + str(ref_row_id), + ) + )) + def get_nested_relations_rows_list_uri( self, project: NocoDBProject, @@ -86,7 +108,7 @@ def get_project_tables_uri( )) def get_table_meta_uri( - self, tableId: str, operation: str = None, + self, tableId: str, operation: Optional[str] = None, ) -> str: additional_path = [] if operation is not None: @@ -100,7 +122,7 @@ def get_table_meta_uri( )) def get_column_uri( - self, columnId: str, operation: str = None, + self, columnId: str, operation: Optional[str] = None, ) -> str: additional_path = [] if operation is not None: diff --git a/nocodb/infra/requests_client.py b/nocodb/infra/requests_client.py index 98e63b5..3e43b1d 100644 --- a/nocodb/infra/requests_client.py +++ b/nocodb/infra/requests_client.py @@ -103,6 +103,22 @@ def table_find_one( params=get_query_params(filter_obj, params), ).json() + def table_row_relation_create( + self, + project: NocoDBProject, + table: str, + relation_type: str, + row_id: int, + column_name: str, + ref_row_id: int, + ) -> dict: + return self._request( + "POST", + self.__api_info.get_row_relation_create_uri( + project, table, relation_type, row_id, column_name, ref_row_id + ), + ).json() + def table_row_nested_relations_list( self, project: NocoDBProject, diff --git a/nocodb/nocodb.py b/nocodb/nocodb.py index 3d7eb07..6a456b8 100644 --- a/nocodb/nocodb.py +++ b/nocodb/nocodb.py @@ -32,7 +32,7 @@ def get_header(self) -> dict: pass -class APIToken: +class APIToken(AuthToken): def __init__(self, token: str): self.__token = token @@ -40,7 +40,7 @@ def get_header(self) -> dict: return {"xc-token": self.__token} -class JWTAuthToken: +class JWTAuthToken(AuthToken): def __init__(self, token: str): self.__token = token @@ -101,6 +101,17 @@ def table_row_delete( ) -> int: pass + @abstractmethod + def table_row_relation_create( + self, + project: NocoDBProject, + relation_type: str, + row_id: int, + column_name: str, + ref_row_id: int, + ) -> dict: + pass + @abstractmethod def table_row_nested_relations_list( self,