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?
This question is related to
javascript
html
database
sqlite
You could use SQL.js which is the SQLlite lib compiled to JavaScript and store the database in the local storage introduced in HTML5.
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:
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
IMHO, the best way is to call Python using POST via AJAX and do everything you need to do with the DB within Python, then return the result to the javascript. json and sqlite support in Python is awesome and it's 100% built-in within even slightly recent versions of Python, so there is no "install this, install that" pain. In Python:
import sqlite3
import json
...that's all you need. It's part of every Python distribution.
@Sedrick Jefferson asked for examples, so (somewhat tardily) I have written up a stand-alone back-and-forth between Javascript and Python here.
My fork of sql.js has now be merged into the original version, on kriken's repo.
The good documentation is also available on the original repo.
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.
What about using something like PouchDB? http://pouchdb.com/
Source: Stackoverflow.com