2

Is there a way, with SQLite3 for Node, to perform a query and either return it as a CSV file that I can then save locally, or have it save locally, automatically.

db.all("SELECT * FROM example WHERE foo = 'bar'", function (error, data) {
  // returns a JSON, I want a CSV file
});

Perhaps, something that can leverage or execute the commands presented in: How do I save the result of a query as a CSV file?

Here's an example of what a solution might look like:

db.save("SELECT * FROM example WHERE foo = 'bar'", directory, filename, cb)
Community
  • 1
  • 1
kuanb
  • 1,618
  • 2
  • 20
  • 42
  • Surely you could simply convert the data object to a CSV-style string... – Colonel Thirty Two Nov 13 '15 at 22:06
  • I could, except that the file I want to convert is ~1 GB. So I'd like to either stream the object in and convert it piecemeal, or I would like to have the operation performed as an export from SQL so I am no holding this massive JSON in memory. – kuanb Nov 13 '15 at 22:24
  • Use the [`Statement#each`](https://github.com/mapbox/node-sqlite3/wiki/API) API. – Colonel Thirty Two Nov 13 '15 at 22:37
  • I could use that, which lead me to a different problem, which I've brought up here: http://stackoverflow.com/questions/33702860/node-sqlites-db-each-using-large-amount-of-memory-for-broad-queries – kuanb Nov 13 '15 at 22:42

0 Answers0