Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlite in chrome

Is it possible to make chrome extension that interacts with sqlite database similarly as firefox extension? Could you give me some advise or link where is more info about developing chrome extension interacting with sqlite?

thank you

like image 893
xralf Avatar asked Jun 01 '11 12:06

xralf


People also ask

Can I use SQLite in browser?

You can use Web SQL API which is an ordinary SQLite database in your browser and you can open/modify it like any other SQLite databases for example with Lita. Chrome locates databases automatically according to domain names or extension id.

Where does Chrome save its SQLite database to?

Chrome Cookies are stored in the 'Cookies' SQLite database (located in the Network folder), within the 'cookies' table. Chrome Downloads are stored in the 'History' SQLite database, within the 'downloads' and 'downloads_url_chains' tables.


2 Answers

You can use Web SQL API which is an ordinary SQLite database in your browser and you can open/modify it like any other SQLite databases for example with Lita.

Chrome locates databases automatically according to domain names or extension id. A few months ago I posted on my blog short article on how to delete Chrome's database because when you're testing some functionality it's quite useful.

like image 112
martin Avatar answered Oct 20 '22 12:10

martin


You might be able to make use of sql.js.

sql.js is a port of SQLite to JavaScript, by compiling the SQLite C code with Emscripten. no C bindings or node-gyp compilation here.

<script src='js/sql.js'></script> <script>     //Create the database     var db = new SQL.Database();     // Run a query without reading the results     db.run("CREATE TABLE test (col1, col2);");     // Insert two rows: (1,111) and (2,222)     db.run("INSERT INTO test VALUES (?,?), (?,?)", [1,111,2,222]);      // Prepare a statement     var stmt = db.prepare("SELECT * FROM test WHERE col1 BETWEEN $start AND $end");     stmt.getAsObject({$start:1, $end:1}); // {col1:1, col2:111}      // Bind new values     stmt.bind({$start:1, $end:2});     while(stmt.step()) { //         var row = stmt.getAsObject();         // [...] do something with the row of result     } </script> 

sql.js is a single JavaScript file and is about 1.5MiB in size currently. While this could be a problem in a web-page, the size is probably acceptable for an extension.

like image 33
sampathsris Avatar answered Oct 20 '22 11:10

sampathsris