23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

• IndexedDB has a 250MB limit per app and an overall system limit of 375MB on drives smaller<br />

than 32GB, or 4% (to a maximum 20GB) for drives over 32GB. So it could be true that your app<br />

might not have much room to work with anyway, in which case you need to make sure you have<br />

a fallback mechanism. (When the limit is exceeded the APIs will throw a Quota Exceeded<br />

exception.)<br />

• IndexedDB on Windows 8 has no complex key paths—that is, it does not presently support<br />

multiple values for a key or index (multientry).<br />

• By default, access to IndexedDB is given only to <strong>HTML</strong> pages that are part of the app package<br />

and those declared as content URIs. (See the “Local and Web Contexts within the App Host”<br />

section at the beginning of Chapter 3.) Random web pages you might host in an iframe will not<br />

be given access, primarily to preserve space within the 250MB limit for those pages you really<br />

care about in your app. However, you can grant access to arbitrary pages by including the<br />

following tag in your home page and not setting the iframe src attribute until the<br />

DOMContentLoaded or activated event has fired:<br />

<br />

Beyond IndexedDB there are a few other database options for Store apps. For a local relational<br />

database, try SQLite. This is an API that’s suited well for apps written in a language like C#, as described<br />

in Tim Heuer’s blog on the subject, but fortunately, there is a version called SQL.js, which is SQLite<br />

compiled to JavaScript via Emscripten. Very cool! There might also be other JavaScript solutions<br />

available in the community.<br />

If the storage limits for IndexedDB are a concern, you might use the Win32 “Jet” or Extensible<br />

Storage Engine (ESE) APIs (on which the IndexedDB implementation is built). For this you’ll need to write<br />

a WinRT Component wrapper in C# or C++ (the general process for which is in Chapter 16, “WinRT<br />

Components”), since JavaScript cannot get to those APIs directly.<br />

The same is true for other third-party database APIs. So long as that engine uses only the Win32 APIs<br />

allowable for Store apps (listed on the Win32 and COM for Windows Store apps page), they’ll work just<br />

fine.<br />

It’s also worth noting that the OData Library for JavaScript also works great for Store apps to access<br />

online SQL Servers, because the OData protocol itself just works via REST.<br />

Finally, another option for searchable file-backed data is to use the system index by creating a folder<br />

named “indexed” in your local AppData folder. The contents of the files in this folder will be indexed by<br />

the system indexer and can be queried using Advanced Query Syntax (AQS) with the APIs explained<br />

later in “Rich Enumeration with File Queries.” You can also do property-based searched for Windows<br />

properties, making this approach a simple alternative to database solutions.<br />

330

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!