-
-
Notifications
You must be signed in to change notification settings - Fork 154
feat: add csv_attachment component #608
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
Conversation
Hi ! Thank you for the PR. Let's do it, the ability to efficiently download a CSV is a great addition. Indeed, I think we should be able to do that without handlebars (using the csv library that we already include), and reuse the existing csv component name and parameters. This way the component downloads the csv directly when used in header position, and creates a download button when used in the middle of the page. We will need to implement a mechanism to handle row-level parameters cleanly in header components (in HeaderContext), but it can then be reused for the json component |
Hi (again), I would love to reuse the For the handlerbars, that what I thought. |
Hello @mtt-artis ! I just implemented the usage of I would be very grateful if you could test the latest version from master and give your feedback ! |
Hi @lovasoa 👋 Thank you for being so productive. I ran some tests with a PostgreSQL database, and the results look accurate—they’re consistent with the JSON component’s output.
vs {"serial_col":1,"bigserial_col":1,"smallint_col":32767,"integer_col":2147483647,"bigint_col":9223372036854775807,"decimal_col":99999.99999,"numeric_col":99999.99999,"real_col":3.4028234663852886e38,"double_col":1.7976931348623157e308,"money_col":"","char_col":"ZZZZZZZZZZ","varchar_col":"ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ","text_col":"Max Text Value","bytea_col":"","date_col":"9999-12-31","time_col":"23:59:59","timestamp_col":"9999-12-31T23:59:59+00:00","timestamptz_col":"9999-12-31T23:59:59+00:00","interval_col":"","boolean_col":true,"uuid_col":"","inet_col":"","cidr_col":"","json_col":{"max_key":"max_value"},"jsonb_col":{"data":["1","2","3",1,2,3,[],{"max_key":"max_value"},{}],"max_key":"max_value"},"jsonb_arr_col":["1","2","3",1,2,3,[],{"max_key":"max_value"},{}]
I've noticed some differences compared to the Handlebars CSV version:
select
'csv' as component,
'test.csv' as filename,
'\t' as delimiter,
'?' as quote,
TRUE as bom;
select * from all_data_types;
|
The fact that this query outputs a valid csv is super cool 👍 select
'csv' as component,
'Download my data' as title,
'test.csv' as filename,
'file-download' as icon,
'green' as color,
TRUE as bom;
select * from all_data_types;
select bigserial_col from all_data_types; |
Thanks for the feedback! I'll try to fix the inconsistencies. For the tab separator, I think the problem comes from your query: in sql |
You're right ! select
'csv' as component,
'Download my data' as title,
'test.csv' as filename,
'file-download' as icon,
'green' as color,
E'\t' as separator,
E'\t' as delimiter,
TRUE as bom; |
Another minor inconsistency is that errors in the Handlebars version return an empty file, whereas the CSV stream returns |
thanks @mtt-artis for reporting the issue #608 (comment)
Hi 👋,
This commit follows the discussion in #260 (better late than never!). It implements the
csv_attachment
component to return data as a CSV file.It works, but it feels a bit hacky due to the use of
is_embedded
and Handlebars. Please feel free to make any changes, rename the component, or point me in the right direction.If you like this implementation, I can add the component to the documentation.