Skip to content

Commit

Permalink
feat: updated to new version of deleting database columns (#70)
Browse files Browse the repository at this point in the history
## changes

@kennyjwilli made a breaking change to the API and the syntax for
deleting columns now requires us to specify database ID

- [x] upgraded to new version of low-level SDK built off of the new
openAPI spec
- [x] pinned that version 
- [x] updated readme
- [x] updated the CLI code
  • Loading branch information
sg-s authored Aug 13, 2024
1 parent ced08a1 commit 2d0ee34
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
19 changes: 9 additions & 10 deletions docs/how-to/data-hub/delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,23 @@ To delete multiple rows, databases and folders, run:

## Delete database columns

To delete columns in databases, run:
To delete columns in databases, run the following command, specifying the IDs of the columns to delete and their parent database:

=== "CLI"

```bash
deeporigin data delete --ids <ids> --columns
deeporigin data delete \
--ids <ids> \
--database <database-id> \
--columns
```

!!! warning "Column IDs"
Currently, columns can only be deleted using their IDs, which are distinct from their names. To view the IDs of the columns of a database, run:

```bash
deeporigin data describe <database-id>
```

=== "Python"

```py
from deeporigin.data_hub import api
api.delete_database_column(column_id="col-id")
api.delete_database_column(
column_id="col-id",
database_id="database-id",
)
```
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies = [
"tabulate",
"filetype",
"httpx",
"deeporigin-data-sdk>=0.1.0a6",
"deeporigin-data-sdk==0.1.0a7",
]
dynamic = ["version"]

Expand Down
16 changes: 11 additions & 5 deletions src/cli/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,17 +567,18 @@ def new(self):
},
),
(
["--columns"],
["--database"],
{
"action": "store_true",
"help": "Whether to delete columns or rows/databases/folders [default: False]",
"type": str,
"required": False,
"help": "ID of database that columns are in",
},
),
(
["--json"],
["--columns"],
{
"action": "store_true",
"help": "Whether to return data in JSON format [default: False]",
"help": "Whether to treat IDs as column IDs [default: False]",
},
),
],
Expand All @@ -586,9 +587,14 @@ def delete(self):
"""Delete rows, columns, databases and/or folders"""

if self.app.pargs.columns:
if self.app.pargs.database is None:
raise DeepOriginException(
"Use the --database argument to specify the parent database. To delete a column, the parent database must be specified."
)
for column_id in self.app.pargs.ids:
api.delete_database_column(
column_id=column_id,
database_id=self.app.pargs.database,
client=self._get_client(),
)
print(f"✔︎ Deleted {len(self.app.pargs.ids)} columns")
Expand Down

0 comments on commit 2d0ee34

Please sign in to comment.