Skip to content

Instantly share code, notes, and snippets.

@goyusia
Created November 8, 2018 03:34
Show Gist options
  • Select an option

  • Save goyusia/55903f91a8464368b5f06437dc77b158 to your computer and use it in GitHub Desktop.

Select an option

Save goyusia/55903f91a8464368b5f06437dc77b158 to your computer and use it in GitHub Desktop.
indexedDBShim + dexie + typescript test
const setGlobalVars = require('indexeddbshim');
(global as any).window = global; // We'll allow ourselves to use `window.indexedDB` or `indexedDB` as a global
setGlobalVars(); // See signature below
(window.indexedDB as any).__setConfig({
checkOrigin: false,
});
const Dexie = require('dexie');
var db = new Dexie('friend_database');
db.version(1).stores({
friends: 'name,shoeSize'
});
//
// Put some data into it
//
(db as any).friends.put({ name: 'Nicolas', shoeSize: 8 }).then(function () {
//
// Then when data is stored, read from it
//
return (db as any).friends.get('Nicolas');
}).then(function (friend: any) {
//
// Display the result
//
console.log('Nicolas has shoe size ' + friend.shoeSize);
}).catch(function (error: any) {
//
// Finally don't forget to catch any error
// that could have happened anywhere in the
// code blocks above.
//
console.log('Ooops: ' + error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment