Skip to content
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

Add delete table endpoint to sdk #119

Merged
merged 6 commits into from
Apr 2, 2024
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ _version.py
venv/
tmp/
.vscode/
build/
.DS_Store
Comment on lines +10 to +11
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, those files are noise.
I'm adding them to the ignore so that no one accidentally pushes them.

Any concerns?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope! Just to make sure its not by accident

11 changes: 11 additions & 0 deletions dune_client/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,14 @@ def _patch(self, route: str, params: Any) -> Any:
timeout=self.request_timeout,
)
return self._handle_response(response)

def _delete(self, route: str) -> Any:
helanto marked this conversation as resolved.
Show resolved Hide resolved
"""Generic interface for the DELETE method of a Dune API request"""
url = self._route_url(route)
self.logger.debug(f"DELETE received input url={url}")
response = self.http.delete(
url=url,
headers=self.default_headers(),
timeout=self.request_timeout,
)
return self._handle_response(response)
16 changes: 15 additions & 1 deletion dune_client/api/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
from typing import List, Dict, IO

from dune_client.api.base import BaseRouter
from dune_client.models import DuneError, InsertTableResult, CreateTableResult
from dune_client.models import (
DuneError,
InsertTableResult,
CreateTableResult,
DeleteTableResult,
)


class TableAPI(BaseRouter):
Expand Down Expand Up @@ -99,3 +104,12 @@ def insert_table(
data=data,
)
return InsertTableResult.from_dict(result_json)

def delete_table(self, namespace: str, table_name: str) -> DeleteTableResult:
"""
https://docs.dune.com/api-reference/tables/endpoint/delete
The delete table endpoint allows you to delete an existing table in Dune.
"""

response_json = self._delete(route=f"/table/{namespace}/{table_name}")
return DeleteTableResult.from_dict(response_json)
9 changes: 9 additions & 0 deletions dune_client/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,12 @@ class InsertTableResult(DataClassJsonMixin):
"""

rows_written: int


@dataclass
class DeleteTableResult(DataClassJsonMixin):
"""
Data type returned by table/delete operation
"""

message: str
30 changes: 26 additions & 4 deletions tests/e2e/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
DuneError,
InsertTableResult,
CreateTableResult,
DeleteTableResult,
)
from dune_client.types import QueryParameter
from dune_client.client import DuneClient
Expand Down Expand Up @@ -226,7 +227,7 @@ def test_get_latest_result_with_query_id(self):
results = dune.get_latest_result(self.query.query_id).get_rows()
self.assertGreater(len(results), 0)

@unittest.skip("This is a plus subscription endpoint.")
@unittest.skip("Requires custom namespace and table_name input.")
def test_upload_csv_success(self):
client = DuneClient(self.valid_api_key)
self.assertEqual(
Expand All @@ -238,7 +239,7 @@ def test_upload_csv_success(self):
True,
)

@unittest.skip("This is a plus subscription endpoint.")
@unittest.skip("Requires custom namespace and table_name input.")
def test_create_table_success(self):
# Make sure the table doesn't already exist.
# You will need to change the namespace to your own.
Expand Down Expand Up @@ -268,7 +269,7 @@ def test_create_table_success(self):
),
)

@unittest.skip("This is a plus subscription endpoint.")
@unittest.skip("Requires custom namespace and table_name input.")
def test_insert_table_csv_success(self):
# Make sure the table already exists and csv matches table schema.
# You will need to change the namespace to your own.
Expand All @@ -284,7 +285,7 @@ def test_insert_table_csv_success(self):
InsertTableResult(rows_written=1),
)

@unittest.skip("This is a plus subscription endpoint.")
@unittest.skip("Requires custom namespace and table_name input.")
def test_insert_table_json_success(self):
# Make sure the table already exists and json matches table schema.
# You will need to change the namespace to your own.
Expand All @@ -300,6 +301,27 @@ def test_insert_table_json_success(self):
InsertTableResult(rows_written=1),
)

@unittest.skip("Requires custom namespace and table_name input.")
def test_delete_table_success(self):
# Make sure the table doesn't already exist.
# You will need to change the namespace to your own.
client = DuneClient(self.valid_api_key)

namespace = "test"
table_name = "dataset_e2e_test"

self.assertEqual(
client.delete_table(
namespace=namespace,
table_name=table_name,
),
DeleteTableResult.from_dict(
{
"message": "Table teamwaddah.waddah_test3 successfully deleted",
}
),
)

def test_download_csv_with_pagination(self):
# Arrange
client = DuneClient(self.valid_api_key)
Expand Down
Loading