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

Use datasette.client instead of TableView #74

Merged
merged 1 commit into from
Jun 7, 2021
Merged

Use datasette.client instead of TableView #74

merged 1 commit into from
Jun 7, 2021

Conversation

simonw
Copy link
Owner

@simonw simonw commented Jun 6, 2021

Refs #61. I think this is a good implementation but I want to spend a tiny bit more time thinking it over and testing it before I land this.

Comment on lines +584 to +590
data = (await datasette.client.get(path_with_query_string)).json()
data["rows"] = [dict(zip(data["columns"], row)) for row in data["rows"]]
# If any cells are $base64, decode them into bytes objects
for row in data["rows"]:
for key, value in row.items():
if isinstance(value, dict) and value.get("$base64"):
row[key] = b64decode(value["encoded"])
Copy link
Owner Author

Choose a reason for hiding this comment

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

This block feels a little clumsy - I'm messing around with data["rows"] to compensate for a difference in shape between the JSON and the raw data that came back from view.data(...).

Copy link
Owner Author

Choose a reason for hiding this comment

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

One complexity here is that I'd like to get back dictionaries, rather than an array of arrays that I have to zip() against the columns - but I also need the other stuff in data - in particular here:

def resolve_totalCount(parent, info):
return parent["filtered_table_rows_count"]

Copy link
Owner Author

Choose a reason for hiding this comment

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

So maybe this should be blocked on changes to Datasette's default JSON? simonw/datasette#782

@simonw
Copy link
Owner Author

simonw commented Jun 7, 2021

I think this is fine. I can revisit how it works after redesigning Datasette's default JSON in simonw/datasette#782

@simonw simonw merged commit 289484d into main Jun 7, 2021
@simonw simonw deleted the client-get branch June 7, 2021 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant