sql.js icon indicating copy to clipboard operation
sql.js copied to clipboard

Please Provide a Reader Only Release

Open Riajyuu opened this issue 7 years ago • 14 comments

Hi, I have a repository that requires to read data from SQLite. I'm pretty sure I need only to read data from without writing into it later. I understand 2.6MB is an ideal size but is it possible to provide a reader only release? Thx in advance.

Riajyuu avatar Nov 02 '18 12:11 Riajyuu

Is your goal with a read only version to reduce the size of the javascript? Or protect the data being loaded?

dinedal avatar Nov 02 '18 15:11 dinedal

@dinedal the former

Riajyuu avatar Nov 02 '18 15:11 Riajyuu

You should issue PRAGMA query_only = true; as the first query after the database is loaded, and that will give you the behavior you desire.

https://www.sqlite.org/pragma.html#pragma_query_only

dinedal avatar Nov 02 '18 17:11 dinedal

@dinedal perhaps we have some misunderstanding here: I don't control the sqlite file source at all. It will be provided by my users and I will need to read it and merge data. After that the sqlite file is left behind.

Riajyuu avatar Nov 02 '18 23:11 Riajyuu

Right, you will need to read it, I presume using sql.js?

You will need to either issue an INSERT statements to insert the data, or you are reading the raw database.

I assume from your response that you're not doing the INSERT statements, and are reading the sqlite data directly? If so then you can open the database file, and then issue PRAGMA query_only = true;, and then do your SELECT to read the data out.

Or you are reading the rows in using INSERT statements, just insert the data and then issue PRAGMA query_only = true;, and then do your SELECT to read the data out.

If both are wrong, maybe you could be more specific on what you are loading and how?

dinedal avatar Nov 05 '18 18:11 dinedal

I think this issue is about providing an sql.js file that would be smaller, but would lack the ability to alter the data in the database. The use-case is simple and (I believe) widespread: load a database file from a server and exploit its data on the client.

lovasoa avatar Nov 05 '18 22:11 lovasoa

Unfortunately, sqlite itself does not seem to provide a compilation option for doing this. (https://www.sqlite.org/compile.html). So this feature being implemented is unlikely.

lovasoa avatar Nov 05 '18 22:11 lovasoa

Ahhhhh yes damn when @Riajyuu replied 'the former' I totally flipped it around in my head! Sorry about that.

dinedal avatar Nov 05 '18 22:11 dinedal

Yes, we don't have an easy way to do it in SQLite, we which this project is based off of.

dinedal avatar Nov 05 '18 22:11 dinedal

@lovasoa is right. Except that I don't meet any server. Users must provide a sqlite location in file explorer. Once finished reading data, the sqlite file will be abandoned behind.

Riajyuu avatar Nov 06 '18 05:11 Riajyuu

This page in the SQLite documentation might be of interest: https://www.sqlite.org/footprint.html However, it mentions a reduction of only 3% of the binary size. Other OMIT options from https://www.sqlite.org/compile.html may further reduce the binary size, but no SQLITE_OMIT_INSERT seem to exist.

lovasoa avatar Nov 06 '18 09:11 lovasoa

I just about want to open new issue but I see my issue is already here. I just want to open file and read data and I think load nearly 2MB on web is a waste and on some where has low internet connection and that is a pain :) If you can support another lib like sql_read_only.min.js which is smaller size that would be nicer.

bachvtuan avatar Aug 05 '19 10:08 bachvtuan

@bachvtuan As mentioned above, this library is based on a compilation of sqlite using emscripten. Since SQLite does not offer an option to create a read-only binary, sql.js is very unlikely to provide such an option anytime soon.

lovasoa avatar Aug 05 '19 11:08 lovasoa

For those interested in a lighter alternative to sql.js, you can have a look at google's lovefield

lovasoa avatar Aug 23 '19 10:08 lovasoa