ChromeDB-JS

Tornevall Networks ChromeDB-JS is a small utility to simplify database calls for Chrome (extensions). The idea was born through the extension "Chrome Extension: Network Tools". This part is still quite undocumented, but to create connections between Chrome and a database here's at least a few examples on how to use it. The current version can be downloaded from the link below (it's available but should be tested before considered a "public release").

Download

tornevall_chromedb.js

Updates

As of NetFilter 2.1.0, updating ChromeDB has been an actual requirement. There are new demands from NetFilter that can make it more efficient and that will make a whole new branch for this script.

 

Examples

In the bottom of popup.html, put

popup.html
<script type="text/javascript" src="scripts/popup.js"></script>
<script type="text/javascript" src="scripts/tornevall_chromedb.js"></script>

In popup.js, put this and let's get started

popup.js
    document.addEventListener('DOMContentLoaded', function() {
        var chromeDb = Tornevall_ChromeDB();
        if (chromeDb.openDatabase('MyExample', '1.2.0', 'My example')) {
            var configTable = ["parameter VARCHAR(64) NOT NULL", "value VARCHAR(255) NOT NULL", "PRIMARY KEY (parameter)"];
            var filterTable = ["content VARCHAR(255) NOT NULL, contentType VARCHAR(16) NULL, PRIMARY KEY (content)"];
            chromeDb.createTable("configuration", configTable);
        }
    }

The SELECT query

Picking up data from a database (SELECT) requires a callback, since the function built cannot return data from the direct call, so a query should look like this:

SELECT FROM Example
chromeDb.Select("filter", function(data) {
    /* Putting some actions here */
    document.write(data["response"][0]["content"]);
});

 

More examples

And here's a few examples how to update tables.

Examples: SELECT, INSERT, UPDATE, DELETE
// INSERT INTO
var columnObject = {
    "content":"newsner",
    "contentType":"url"
};
chromeDb.Insert("filter", columnObject);

// SELECT FROM
chromeDb.Select("filter", function(data) {
    document.write(data["response"][0]["content"]);
});

// UPDATE TABLE
var where = {
    "content":"newsner"
};
var columnObject = {
    "content":"newsner.com"
}
chromeDb.Update("filter", columnObject, where);

// DELETE FROM
var conditionObject = {
    "content":"newsner.com"
}
chromeDb.Delete("filter", conditionObject);
  • No labels