Created
November 8, 2018 03:34
-
-
Save goyusia/55903f91a8464368b5f06437dc77b158 to your computer and use it in GitHub Desktop.
indexedDBShim + dexie + typescript test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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