Skip to content

Commit

Permalink
chore(client): list tables without switch instance in datastore debug…
Browse files Browse the repository at this point in the history
… cli (#2931)
  • Loading branch information
jialeicui authored Nov 2, 2023
1 parent 20293d1 commit 0b9b38b
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions client/starwhale/cli/deubg/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ def datastore() -> None:
...


def _get_datastore() -> DataStore:
ins = Instance()
def _get_datastore(ins: Instance) -> DataStore:
if ins.is_cloud:
return RemoteDataStore(ins.url, ins.token)
else:
Expand All @@ -27,20 +26,28 @@ def _get_datastore() -> DataStore:

@datastore.command("tables", help="list tables")
@click.option("-p", "--project", default="", help="project name or id")
def _tables(project: str) -> None:
project_id = Project(project).id
@click.option("-i", "--instance", default="", help="instance alias")
def _tables(project: str, instance: str) -> None:
proj = Project(project)
ins = Instance(instance)
if instance != "" and "/" in project and proj.instance != ins:
raise ValueError(f"instance mismatch: {proj.instance} != {ins}")
proj.instance = ins

project_id = proj.id
console.info(f"list tables in project {project_id}")

prefix = f"project/{project_id}/"
for table in _get_datastore().list_tables([prefix]):
for table in _get_datastore(proj.instance).list_tables([prefix]):
click.echo(table)


@datastore.command("scan", help="get table")
@click.argument("table")
@click.option("-l", "--limit", default=10, help="limit of rows to get, 0 for all")
def _get(table: str, limit: int) -> None:
ds = _get_datastore()
@click.option("-i", "--instance", default="", help="instance alias")
def _get(table: str, limit: int, instance: str) -> None:
ds = _get_datastore(Instance(instance))
for row in ds.scan_tables(tables=[TableDesc(table_name=table)]):
console.print(row)
if limit > 0:
Expand Down

0 comments on commit 0b9b38b

Please sign in to comment.