News for hackers. Stuff that matters.
Re:Show HN: Private, in-browser, CSV-SQL query runner using ... by pdyc on Sunday November 03, 2024 @01:04AM (#42031267)
crashed with big file https://www.papaparse.com/resources/files/big.csv i evaluated sqlite for my tool and wrote about it here https://newbeelearn.com/blog/million-rows-csv-debug-story/

BTW i checked your sqlite.wasm to be quite compact, just 340kb are you doing custom compilation.

Re:Show HN: Private, in-browser, CSV-SQL query runner using ... by freakynit on Sunday November 03, 2024 @01:25AM (#42031316)
Hey, thanks for trying out.

I did check out with the csv you linked. It worked for me. https://ibb.co/cb3SFbR. Before making it live, I did already test it with 100MB+ CSV's having like 10+ columns.

I also checked my sentry integration, but couldn't find any errors to your issue. Seems to me like OS/browser level ram restriction. In case you have anything to help me with debug this, do share..

Im using regular sqlite-wasm. No custom stuff.

Thanks..

Re:Show HN: Private, in-browser, CSV-SQL query runner using ... by itsbrex on Sunday November 03, 2024 @05:18AM (#42032223)
Works on my iPhone with the ‘big.csv’ file as well
Re:Show HN: Private, in-browser, CSV-SQL query runner using ... by freakynit on Sunday November 03, 2024 @07:44AM (#42032739)
Thanks a lot for trying it out and verifying :)
Re:Show HN: Private, in-browser, CSV-SQL query runner using ... by pdyc on Sunday November 03, 2024 @12:26PM (#42034457)
i tested on machine with 4gb ram, also i modified the query to remove the limit i.e. "select * from data"

can you let me know from where you are picking sqlite wasm? i checked here https://sqlite.org/download.html and sqlite wasm shared here is approx 830kb

Edit: never mind checked here https://github.com/sql-js/sql.js/releases/tag/v1.12.0 and its indeed around 330kb.

Re:Show HN: Private, in-browser, CSV-SQL query runner using ... by kfajdsl on Sunday November 03, 2024 @08:00PM (#42037469)
Loading that CSV and running `select * from data` left me with 879MB of memory usage on the tab.
Re:Show HN: Private, in-browser, CSV-SQL query runner using ... by victor106 on Sunday November 03, 2024 @08:43AM (#42033026)
This is cool. Any pointers on how you built this?
Re:Show HN: Private, in-browser, CSV-SQL query runner using ... by freakynit on Monday November 04, 2024 @12:15AM (#42038691)
Hey, thanks...

Almost all the major work is done by sqlite (packaged as wasm binary), with second most by Papaparse library. I just joined these two and put up a decent web ui on top. The only manual thing done by me is schema parsing, which is based on first 1000 rows, and downloading functionality.

Re:Show HN: Private, in-browser, CSV-SQL query runner using ... by nbbaier on Monday November 04, 2024 @11:48AM (#42043362)
How are you doing the schema parsing?
Re:Show HN: Private, in-browser, CSV-SQL query runner using ... by freakynit on Monday November 04, 2024 @12:31PM (#42043903)
(1.) Since this is a javascript environment, the types are pretty minimal and just one of each top level type (unlike languages like java or C, which, for example, clould have int, float, double, etc. for just one `number` top-level type). These, here, in javascript, are: number, string, boolean, object, null/undefined.

(2.) Then I use `typeof` operator for each field to determine appropriate javascript type.

(3.) Then, I map these javascript types to sqlite types using this mapping:::

const typeMapping = { 'number': 'REAL', 'string': 'TEXT', 'boolean': 'INTEGER', 'object': 'TEXT', 'undefined': 'TEXT' };

(4.) Then, I generate create table sql's fields declaration part. This also handles an edge case where if first 1000 rows (used for schema generation) of a particular field are all null/undefined, I default to using sqlite's TEXT type using this:::

const columns = fields.map(field => `'${field}' ${typeMapping[columnTypes[field]] || 'TEXT'}`);

(5.) Finally, I create sqlite table:::

const createTableSQL = `CREATE TABLE data (${columns.join(', ')});`;

db = new SQL.Database();

db.run(createTableSQL);

Thanks..

Re:Show HN: Private, in-browser, CSV-SQL query runner using ... by nbbaier on Monday November 04, 2024 @12:41PM (#42044020)
Nice explainer, thanks!
Re:Show HN: Private, in-browser, CSV-SQL query runner using ... by freakynit on Monday November 04, 2024 @12:51PM (#42044148)
Welcome :)