SQLite Universal WinJS Component
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
WinRT Javascript Helper Files
SQLite Universal WinJS Component.sln


SQLite Universal WinJS Component

SQLite Universal WinJS Component for Javascript Windows Store Apps running on the Windows 10 Universal App Platform.


SQLite Universal WinJS consists of two parts: 1) WinRT C++ universal component named SQLite3Component and 2) A JavaScript file called SQLiteHelper that builds upon the component and simplifies use.

To use this component, copy the SQLiteUniversalWinJS folder to the root of your app's solution folder. Then in Visual Studio, go to File -> Add -> Existing Project, and choose the file SQLiteUniversalWinJS.vcxproj found in *[YourSolutionFolder]\SQLiteUniversalWinJS*
Next, add a reference to the component in your app solution's main project in Visual Studio by going to Project -> Add Reference ... , where you go to Projects, and enable the SQLiteUniversalWinJS project as a reference.
Finally, copy the JavaScript file SQLiteHelper.js from the WinRT Javascript Helper Files folder to the js folder in your solution's main project, and reference it in your default.html file to use it.


This component uses the SQLite for Universal App Platform extension, by the SQLite Development Team. (Current version = 3.15.2) The extension is required for the component to work.


One custom JavaScript method in SQLiteHelper.js is checkDatabaseAsync(databaseFolder, databaseFileName), which, will check if a global database object is defined, and if not, will define one, before returning a WinJS.Promise object.
To use, customize the MyGlobals.database variable in it, to be the variable name you use for your global database object.


checkDatabaseAsync().then(function () {
    MyGlobals.database.executeAsync("SELECT * FROM Books").then(function (rows) {
        rows.forEach(function (row) {
            var book = {
                bookName: row.getFirstValueByName("bookName")
            // do something after forEach here

```javascript function createDB() { // Create the request to open the database, named BookDB. If it doesn't exist, create it. var database;

SQLite.Database.openDatabaseInFolderAsync(Windows.Storage.ApplicationData.current.roamingFolder, "BookDB.sqlite").then( function (openedOrCreatedDatabase) { database = openedOrCreatedDatabase; return executeStatementsAsTransactionAsync(database, [ "CREATE TABLE IF NOT EXISTS books (id INTEGER PRIMARY KEY UNIQUE, title TEXT, authorid INTEGER);", "CREATE TABLE IF NOT EXISTS authors (id INTEGER PRIMARY KEY UNIQUE, name TEXT);", "CREATE TABLE IF NOT EXISTS checkout (id INTEGER PRIMARY KEY UNIQUE, status INTEGER);" ]); }).then(function () { if (database) { database.close(); database = null; } }, function (err) { if (database) { database.close(); database = null; } WinJS.log && WinJS.log("Database open failure: " + err, "sample", "error"); }); }

## Credits
This is a port of the Windows 8.1 Component by Dave Risney found at https://code.msdn.microsoft.com/windowsapps/Universal-JavaScript-5728abdb
For more information, go to http://blogs.windows.com/buildingapps/2014/07/02/writing-a-sqlite-wrapper-component-for-universal-windows-apps/