Skip to content

Commit 0f368f1

Browse files
committed
csv documentation
1 parent 84a938f commit 0f368f1

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
select 'csv' as component, 'example.csv' as filename;
2+
select * from component;

examples/official-site/sqlpage/migrations/01_documentation.sql

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -810,14 +810,38 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
810810
('separator', 'How individual values should be separated in the CSV. "," by default, set it to "\t" for tab-separated values.', 'TEXT', TRUE, TRUE),
811811
('title', 'The text displayed on the download button.', 'TEXT', TRUE, FALSE),
812812
('filename', 'The name of the file that should be downloaded (without the extension).', 'TEXT', TRUE, TRUE),
813-
('icon', 'Name of the icon (from tabler-icons.io) to display in the button.', 'ICON', TRUE, TRUE),
814-
('color', 'Color of the button', 'COLOR', TRUE, TRUE),
815-
('size', 'The size of the button (e.g., sm, lg).', 'TEXT', TRUE, TRUE),
813+
('icon', 'Name of the icon (from tabler-icons.io) to display in the button. Ignored when used as a header component.', 'ICON', TRUE, TRUE),
814+
('color', 'Color of the button. Ignored when used as a header component.', 'COLOR', TRUE, TRUE),
815+
('size', 'The size of the button (e.g., sm, lg). Ignored when used as a header component.', 'TEXT', TRUE, TRUE),
816816
('bom', 'Whether to include a Byte Order Mark (a special character indicating the character encoding) at the beginning of the file. This is useful for Excel compatibility.', 'BOOLEAN', TRUE, TRUE)
817817
) x;
818818

819819
INSERT INTO example(component, description, properties) VALUES
820-
('csv', 'CSV download button',
820+
('csv', '
821+
### Header component: creating a CSV download URL
822+
823+
You can create a page that will trigger a download of the CSV file when the user visits it.
824+
The contents will be streamed efficiently from the database to the browser, without being fully loaded in memory.
825+
This makes it possible to download even very large files without overloading the database server, the web server, or the client''s browser.
826+
827+
#### `csv_download.sql`
828+
829+
```sql
830+
select ''csv'' as component, ''example.csv'' as filename;
831+
SELECT * FROM my_large_table;
832+
```
833+
834+
#### `index.sql`
835+
',
836+
json('[{"component":"button"}, {"title": "Download my data", "link": "/examples/csv_download.sql"}]')),
837+
('csv', '
838+
### CSV download button
839+
840+
This will generate a button to download the CSV file.
841+
The button element itself will embed the entire contents of the CSV file, so it should not be used for large files.
842+
The file will be entirely loaded in memory on the user''s browser, even if the user does not click on the button.
843+
For smaller files, this is easier and faster to use than creating a separate SQL file to generate the CSV.
844+
',
821845
json('[{"component":"csv", "title": "Download my data", "filename": "people", "icon": "file-download", "color": "green", "separator": ";", "bom": true}, '||
822846
'{"Forename": "Ophir", "Surname": "Lojkine", "Pseudonym": "lovasoa"},' ||
823847
'{"Forename": "Linus", "Surname": "Torvalds", "Pseudonym": "torvalds"}]'));

0 commit comments

Comments
 (0)