duckdb-web
duckdb-web copied to clipboard
Add missing imports to Wasm documentation example
Discussed in https://github.com/duckdb/duckdb/discussions/14431
Originally posted by lucasl84 October 18, 2024 Hi,
I needed to use the WASM DuckDB for some tests. I was reading the documentation for loading a CSV from a static served file. Is it really too much to ask to have better documentation. In the snippet I'm referring to Apache Arrow is referenced and nowhere imported. Also what c is supposed to be in c.insertCSVFromPath? I got that is the connection, but please avoid this coding/documentation style, is confusing and time wasting (especially for someone that just got started developing or developing with DuckDB). The missing imports I'm referring to are:
import { Int32, Utf8 } from 'apache-arrow'; // Also remove the `arrow.` prefix.
I think examples should always be self-contained: I should be able to copy/paste a snippet and run it without any other extra code or modifications from elsewhere. As I have used DuckDB in the past with Python when providing the columns for CSVs this is done for example with the following types:
duckdb.sql(
f"""
INSERT INTO table (
SELECT *
FROM read_csv(
'/SOME_PATH',
columns={{
'COLUMN_A': 'INT',
'COLUMN_B': 'STRING',
'COLUMN_C': 'BOOL',
}}
)
)
"""
)
In the above snippet the INT, STRING and BOOL types work but in the JS version I need to use Apache Arrow types. Would I also need to use different datatypes library/syntax if I use other existing DuckDB bindings? Couldn't be possible to use plain strings to reference datatypes as above and allow DuckDB behind scenes to do the appropriate conversions for each binding?
Thanks, Lucas.