Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 909
Pal Szasz Avatar asked Nov 02 '12 09:11

Pal Szasz


People also ask

Can JavaScript query database?

If you want to get information from your database using javascript, you'll need to have javascript ask PHP to query the database through an AJAX call to a PHP script. In summary: Javascript can't connect to the database but it can ask PHP to do so.

Can SQLite be accessed remotely?

SQLite is designed for situations where the data and application coexist on the same machine. SQLite can still be made to work in many remote database situations, but a client/server solution will usually work better in that scenario.


1 Answers

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.

like image 112
Minko Gechev Avatar answered Sep 23 '22 22:09

Minko Gechev