Skip to content

Add a new relation #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions nocodb/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from enum import Enum
from typing import Optional
from urllib.parse import urljoin
from .nocodb import NocoDBProject

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
16 changes: 16 additions & 0 deletions nocodb/infra/requests_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 13 additions & 2 deletions nocodb/nocodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ def get_header(self) -> dict:
pass


class APIToken:
class APIToken(AuthToken):
def __init__(self, token: str):
self.__token = token

def get_header(self) -> dict:
return {"xc-token": self.__token}


class JWTAuthToken:
class JWTAuthToken(AuthToken):
def __init__(self, token: str):
self.__token = token

Expand Down Expand Up @@ -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,
Expand Down