Giter Site home page Giter Site logo

sqlite-universal-winjs-component's Introduction

SQLite Universal WinJS Component

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

Setup

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.

Dependencies

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.

Usage

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.

Examples

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
        });
    });
});

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/

sqlite-universal-winjs-component's People

Contributors

cloudcrypt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

sushitee

sqlite-universal-winjs-component's Issues

Error with x64

I followed the instructions but here what I got when I tried to run my app in x64 (it works fine with x86)

Error C1083 Cannot open precompiled header file: 'x64\Debug\pch.pch': No such file or directory

Loading SQLiteUniversalWinJS to solution

Hey,

Great repo - thanks for your guide! Currently having problems to add the SQLiteUniversalWinJS project to my solution:

Running VS2013
I already installed a vsix extension of SQLite (current version seems to be 3.11.0)

Also changed the version number on the SQLiteUniversalWinJS.vcxproj but didn't had affect - same error,

Any help is appreciated!

SQLite component is failing on Windows App Cert Kit 10.0

Hey,

I just realised that the App Cert Kit for Store fails on this C++ component on test of supported APIs:

API sqlite3_bind_text in sqlite3.dll wird für diesen Anwendungstyp nicht unterstützt. SQLiteUniversalWinJS.dll ruft diese API auf.
API sqlite3_close in sqlite3.dll wird für diesen Anwendungstyp nicht unterstützt. SQLiteUniversalWinJS.dll ruft diese API auf.
API sqlite3_column_count in sqlite3.dll wird für diesen Anwendungstyp nicht unterstützt. SQLiteUniversalWinJS.dll ruft diese API auf.
API sqlite3_column_name in sqlite3.dll wird für diesen Anwendungstyp nicht unterstützt. SQLiteUniversalWinJS.dll ruft diese API auf.
API sqlite3_column_text in sqlite3.dll wird für diesen Anwendungstyp nicht unterstützt. SQLiteUniversalWinJS.dll ruft diese API auf.
API sqlite3_exec in sqlite3.dll wird für diesen Anwendungstyp nicht unterstützt. SQLiteUniversalWinJS.dll ruft diese API auf.
API sqlite3_finalize in sqlite3.dll wird für diesen Anwendungstyp nicht unterstützt. SQLiteUniversalWinJS.dll ruft diese API auf.
API sqlite3_mprintf in sqlite3.dll wird für diesen Anwendungstyp nicht unterstützt. SQLiteUniversalWinJS.dll ruft diese API auf.
API sqlite3_open_v2 in sqlite3.dll wird für diesen Anwendungstyp nicht unterstützt. SQLiteUniversalWinJS.dll ruft diese API auf.
API sqlite3_prepare in sqlite3.dll wird für diesen Anwendungstyp nicht unterstützt. SQLiteUniversalWinJS.dll ruft diese API auf.
API sqlite3_step in sqlite3.dll wird für diesen Anwendungstyp nicht unterstützt. SQLiteUniversalWinJS.dll ruft diese API auf.
API sqlite3_temp_directory in sqlite3.dll wird für diesen Anwendungstyp nicht unterstützt. SQLiteUniversalWinJS.dll ruft diese API auf.

I just created a new universal app project on this github solution file and added SQLiteUniversalWinJS as reference to it.

Anyone experienced similar problems? 😞 Running Win8.1 with VS2015, Windows SDK 10.0.10586.0 and Windows App Cert Kit 10.0.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.