'Is it possible to access an SQLite database from JavaScript?
I have a set of HTML files and a SQLite database, which I would like to access from the browser, using the file:// scheme. Is it possible to access the database and create queries (and tables) using JavaScript?
Solution 1:[1]
Actually the answer is yes. Here is an example how you can do this: http://html5doctor.com/introducing-web-sql-databases/
The bad thing is that it's with very limited support by the browsers.
More information here HTML5 IndexedDB, Web SQL Database and browser wars
PS: As @Christoph said Web SQL is no longer in active maintenance and the Web Applications Working Group does not intend to maintain it further so look here https://developer.mozilla.org/en-US/docs/IndexedDB.
SQL.js
EDIT
As @clentfort said, you can access SQLite database with client-side JavaScript by using SQL.js.
Solution 2:[2]
You could use SQL.js which is the SQLlite lib compiled to JavaScript and store the database in the local storage introduced in HTML5.
Solution 3:[3]
Up to date answer
My fork of sql.js has now be merged into the original version, on a dedicated repo.
The good documentation is also available on the original repo.
Original answer (outdated)
You should use the newer version of sql.js. It is a port of sqlite 3.8, has a good documentation and is actively maintained (by me). It supports prepared statements, and BLOB data type.
Solution 4:[4]
One of the most interesting features in HTML5
is the ability to store data locally and to allow the application to run offline. There are three different APIs that deal with these features and choosing one depends on what exactly you want to do with the data you're planning to store locally:
- Web storage: For basic local storage with key/value pairs
- Offline storage: Uses a manifest to cache entire files for offline use
- Web database: For relational database storage
For more reference see Introducing the HTML5 storage APIs
And how to use
http://cookbooks.adobe.com/post_Store_data_in_the_HTML5_SQLite_database-19115.html
Solution 5:[5]
What about using something like PouchDB? http://pouchdb.com/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | maxkoryukov |
Solution 2 | maxkoryukov |
Solution 3 | |
Solution 4 | |
Solution 5 | theamoeba |