<p>Best recommendations for accessing and manipulation of sqlite databases from JavaScript.</p>

[{'answer_id': 61987, 'author': 'Mike Stone', 'author_id': 122, 'author_profile': 'https://Stackoverflow.com/users/122', 'pm_score': 5, 'selected': True, 'text': "<p>Well, if you are working on client side JavaScript, I think you will be out of luck... browsers tend to sandbox the JavaScript environment so you don't have access to the machine in any kind of general capacity like accessing a database.</p>\n\n<p>If you are talking about an SQLite DB on the server end accessed from the client end, you could set up an AJAX solution that invokes some server side code to access it.</p>\n\n<p>If you are talking about Rhino or some other server side JavaScript, you should look into the host language's API access into SQLite (such as the JDBC for Rhino).</p>\n\n<p>Perhaps clarify your question a bit more...?</p>\n"}, {'answer_id': 61991, 'author': 'Cebjyre', 'author_id': 1612, 'author_profile': 'https://Stackoverflow.com/users/1612', 'pm_score': 4, 'selected': False, 'text': '<p><a href="http://gears.google.com/" rel="noreferrer">Google Gears</a> has a built-in sqlite database - but you\'ll need to ensure that people have it installed if you plan to rely on it.</p>\n\n<p>Depending on your circumstances, you may be able to enforce installation, otherwise you should treat it as a nice-to-have, but have graceful degradation so that the site still works if it isn\'t installed.</p>\n'}, {'answer_id': 63136, 'author': 'Joel Anair', 'author_id': 7441, 'author_profile': 'https://Stackoverflow.com/users/7441', 'pm_score': 2, 'selected': False, 'text': '<p>If you\'re running privileged scripts in Windows (either in an HTA or WSH), you can access ODBC data sources using an "ADODB.Recordset" ActiveXObject.</p>\n\n<p>If you\'re talking about client side on a web page, the above post re: Google Gears is your best bet.</p>\n'}, {'answer_id': 63588, 'author': 'user7878', 'author_id': 7878, 'author_profile': 'https://Stackoverflow.com/users/7878', 'pm_score': 3, 'selected': False, 'text': '<p>If you\'re looking to access SQLite databases on the browser (ie. client side) you\'ll need your browser to support it. You can do it with SpiderApe <a href="http://spiderape.sourceforge.net/plugins/sqlite/" rel="noreferrer">http://spiderape.sourceforge.net/plugins/sqlite/</a> which assumes that browser is Mozilla based (ie. with SQLite support). You\'ll still need to allow access to the underlying libraries ( <a href="http://www.mozilla.org/projects/security/components/signed-scripts.html" rel="noreferrer">http://www.mozilla.org/projects/security/components/signed-scripts.html</a> )</p>\n\n<p>If you\'re looking for serverside access from Javascript programs to SQLite databases there are several options: JSDB is one <a href="http://www.jsdb.org/" rel="noreferrer">http://www.jsdb.org/</a> ; JSEXT another <a href="http://jsext.sourceforge.net/" rel="noreferrer">http://jsext.sourceforge.net/</a> ; and jslibs another <a href="http://code.google.com/p/jslibs/" rel="noreferrer">http://code.google.com/p/jslibs/</a></p>\n\n<p>-- MV</p>\n'}, {'answer_id': 810530, 'author': 'jcburns', 'author_id': 99211, 'author_profile': 'https://Stackoverflow.com/users/99211', 'pm_score': 0, 'selected': False, 'text': '<p>On a Mac? Take a look at Gus Meuller\'s JSTalk, which leverages Scripting Bridge and Patrick Geiller\'s JSCocoa.</p>\n\n<p>Gus talks specifically about the Sqlite support here: <a href="http://gusmueller.com/blog/archives/2009/03/jstalk_extras.html" rel="nofollow noreferrer">http://gusmueller.com/blog/archives/2009/03/jstalk_extras.html</a> ...works great.</p>\n'}, {'answer_id': 3380801, 'author': 'Brain90', 'author_id': 341959, 'author_profile': 'https://Stackoverflow.com/users/341959', 'pm_score': 2, 'selected': False, 'text': '<p>You can perform it with XUL API on mozilla firefox stack. This some tutorial about it:\n<a href="http://www.arashkarimzadeh.com/articles/10-xul/25-sqlite-api-for-xul-application-using-javascript.html" rel="nofollow noreferrer">http://www.arashkarimzadeh.com/articles/10-xul/25-sqlite-api-for-xul-application-using-javascript.html</a></p>\n'}, {'answer_id': 10595180, 'author': 'Peter Aron Zentai', 'author_id': 1269946, 'author_profile': 'https://Stackoverflow.com/users/1269946', 'pm_score': 0, 'selected': False, 'text': '<p><a href="http://jaydata.org" rel="nofollow">JayData</a> also provides a toolkit to work with sqLite/webSql using JavaScript. You\'ll need a browser,Rhine or Nodejs to run the thing though.</p>\n'}, {'answer_id': 11110639, 'author': 'Juicy Scripter', 'author_id': 155033, 'author_profile': 'https://Stackoverflow.com/users/155033', 'pm_score': 5, 'selected': False, 'text': '<p>There a project called <a href="https://github.com/kripken/sql.js"><code>sql.js</code></a> which is a port of SQLite in JavaScript.</p>\n\n<blockquote>\n  <p>sql.js is a port of SQLite to JavaScript, by compiling the SQLite C code with Emscripten.</p>\n</blockquote>\n'}, {'answer_id': 13155302, 'author': 'd.popov', 'author_id': 1407302, 'author_profile': 'https://Stackoverflow.com/users/1407302', 'pm_score': 2, 'selected': False, 'text': '<p>The <a href="https://github.com/kripken/sql.js" rel="nofollow">sql.js</a> library will enable you to call SQL queries on the client side. with that libray, you can easily stream the whole data between the server and the client by calling .open(data) and .exportData(). this is very handy.</p>\n\n<p>in addition HTML5 has <a href="http://diveintohtml5.info/storage.html" rel="nofollow">storage capabilities</a>, but as new technology standard, you can not assume that all the clients will support that.</p>\n\n<p><a href="http://brian.io/lawnchair/" rel="nofollow">Lawnchair</a> is very good option if you are not stuck with SQL, as it gives an easy to use key/value approach. these two libraries make a complete solution for working with sql database on client-side.</p>\n\n<p>Another good storage library is <a href="http://www.jstorage.info/" rel="nofollow">jstorage</a>. it can be used to conserve the data from the "sql.js" on the client. It supports a large variety of browsers (including mobile browsers, and IE7 and IE7 !), and even survives browser crashes.</p>\n'}, {'answer_id': 23878874, 'author': 'lovasoa', 'author_id': 3579309, 'author_profile': 'https://Stackoverflow.com/users/3579309', 'pm_score': 5, 'selected': False, 'text': '<h1>Panorama of javascript SQLite solutions</h1>\n\n<h2>In the browser</h2>\n\n<p>If you want to access a SQLite database from inside a web browser, you don\'t have many solutions.</p>\n\n<h3>sql.js</h3>\n\n<p>The SQLite C library has been <strong>ported to javascript</strong> using <a href="https://github.com/kripken/emscripten">emscripten</a>. The port was started under the name of <a href="https://github.com/kripken/sql.js"><code>sql.js</code></a> by Alon Zakai (who is also the author of emscripten). I am the current maintainer of this library.</p>\n\n<p>The API goes like:</p>\n\n<pre><code>&lt;script src=\'js/sql.js\'&gt;&lt;/script&gt;\n&lt;script&gt;\n    //Create the database\n    var db = new SQL.Database();\n    // Run a query without reading the results\n    db.run("CREATE TABLE test (col1, col2);");\n    // Insert two rows: (1,111) and (2,222)\n    db.run("INSERT INTO test VALUES (?,?), (?,?)", [1,111,2,222]);\n\n    // Prepare a statement\n    var stmt = db.prepare("SELECT * FROM test WHERE a BETWEEN $start AND $end");\n    stmt.getAsObject({$start:1, $end:1}); // {col1:1, col2:111}\n\n    // Bind new values\n    stmt.bind({$start:1, $end:2});\n    while(stmt.step()) { //\n        var row = stmt.getAsObject();\n        // [...] do something with the row of result\n    }\n&lt;/script&gt;\n</code></pre>\n\n<h3>Web SQL</h3>\n\n<p>The W3C had started to work on a native API for executing SQL inside the browser, called <strong>web sql</strong>. An example of use of that API:</p>\n\n<pre><code>var db = openDatabase(\'mydb\', \'1.0\', \'my first database\', 2 * 1024 * 1024);\ndb.transaction(function (tx) {\n  tx.executeSql(\'CREATE TABLE IF NOT EXISTS foo (id unique, text)\');\n  tx.executeSql(\'INSERT INTO foo (id, text) VALUES (1, "synergies")\');\n});\n</code></pre>\n\n<p>However, the project has been <strong>abandoned</strong>. Thus it\'s not widely supported. See: <a href="http://caniuse.com/sql-storage">http://caniuse.com/sql-storage</a></p>\n\n<h2>In node</h2>\n\n<p>If you write client-side javascript, in node, you have a little more choices. See: <a href="https://www.npmjs.org/search?q=sqlite">https://www.npmjs.org/search?q=sqlite</a> .</p>\n\n<h3>node-sqlite3</h3>\n\n<p>If you have a compilation toolchain, and can don\'t care about having to compile your application for different platforms (or target only one platform), I would advise that you use <a href="https://www.npmjs.org/package/sqlite3"><code>node-sqlite3</code></a>. It is fast (much faster than <code>sql.js</code>), has a complete API and a good documentation. An example of the API is as follow:</p>\n\n<pre><code>var sqlite3 = require(\'sqlite3\').verbose();\nvar db = new sqlite3.Database(\':memory:\');\n\ndb.serialize(function() {\n  db.run("CREATE TABLE lorem (info TEXT)");\n\n  var stmt = db.prepare("INSERT INTO lorem VALUES (?)");\n  for (var i = 0; i &lt; 10; i++) {\n      stmt.run("Ipsum " + i);\n  }\n  stmt.finalize();\n\n  db.each("SELECT rowid AS id, info FROM lorem", function(err, row) {\n      console.log(row.id + ": " + row.info);\n  });\n});\n\ndb.close();\n</code></pre>\n\n<h3>sql.js</h3>\n\n<p>Yes, again. <a href="https://github.com/lovasoa/sql.js"><code>sql.js</code></a> can be used from node.\nThis is the solution if you want a pure javascript application. However, it will be slower than the previous solution.</p>\n\n<p>Here is an example of how to use <code>sql.js</code> from node:</p>\n\n<pre><code>var fs = require(\'fs\');\nvar SQL = require(\'sql.js\');\nvar filebuffer = fs.readFileSync(\'test.sqlite\');\n\ndb.run("INSERT INTO test VALUES (?,?,?)", [1, \'hello\', true]);  -- corrected INT to INTO\n\n\nvar data = db.export();\nvar buffer = new Buffer(data);\nfs.writeFileSync("filename.sqlite", buffer);\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/61972', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6390/']