Skip to content
Snippets Groups Projects

Resolve "API to delete table"

Merged Pierre Chanial requested to merge 6-api-to-delete-table into master
8 files
+ 255
166
Compare changes
  • Side-by-side
  • Inline
Files
8
+ 20
2
@@ -4,7 +4,7 @@ import os
from typing import Literal
import requests
from fastapi import APIRouter, Depends, HTTPException, status
from fastapi import APIRouter, Depends, HTTPException, Response, status
from pandas import DataFrame
from sqlalchemy import text
from sqlalchemy.engine import Connection
@@ -14,7 +14,7 @@ from sqlalchemy.orm import Session
from ... import db
from ...db.dbadmin import begin_session
from ...db.dbprojects import project_engines
from ...db.dbprojects.operations import select_table_column_names
from ...db.dbprojects.operations import drop_table, select_table_column_names
from ...schemas import (
BodyCreateTableFromESAPGatewayQuery,
BodyCreateTableFromMapping,
@@ -197,3 +197,21 @@ def get_table_column_names(
) -> list[str]:
"""Returns the column names of a table."""
return select_table_column_names(connection, dataset, table)
@router.delete(
'/projects/{project}/datasets/{dataset}/tables/{table}', summary='Deletes a table.'
)
def delete_table(
project: str,
dataset: str,
table: str,
*,
session: Session = Depends(get_session),
connection: Connection = Depends(get_connection),
) -> Response:
"""Deletes a table."""
table_name = f'{project}.{dataset}.{table}'
db.table.delete_by_name(session, table_name)
drop_table(connection, table_name)
return Response(status_code=status.HTTP_204_NO_CONTENT)
Loading