Dexie.js

A Minimalistic Wrapper for IndexedDB

APACHE-2.0 License

Downloads
2.2M
Stars
10.7K
Committers
98
Dexie.js - Dexie v1.4.2

Published by dfahlander about 8 years ago

Dexie.js - Dexie v1.4.1

Published by dfahlander over 8 years ago

Fixes issue #264

Dexie.js - Dexie v1.4.0

Published by dfahlander over 8 years ago

Optimized, simplified and debug friendlier.

Much of the code base has been rewritten since v1.3.6 for the purposes of both optimization and code simplification.

Async stacks for Easier Debugging

  • Async stack support on all thrown errors in debug mode.
  • Debug mode is defined via Dexie.debug static property.
  • Dexie.debug will default to true when served from localhost.
Dexie.debug = true; // Enables long stacks (Default on when served from localhost)

db.friends.toArray(friends => {
    return friends.map(friend => friend.name);
}).then (names => {
    console.log(names.join(', ');
}).then (()=> {
    throw new Error ("oops!");
}).catch (function (e) {
    console.error ("Oops: " + e.stack); // Will see long stacks containing async flow:
         // Error: oops!
         //    at yourSource:file:line
         // From previous:
         //    at yourSource of prevous promise
         //    ...
         // From previous:
         //    at yourSrouce even earlier...
         //    ...
});

Reusable Collections

If you prepare a collection:

var collection = db.friends.where('age').above(25);

...you can reuse that collection in any transaction later:

db.transaction('r', db.friends, function() {
    collection.toArray(function (result) {
        console.log(JSON.stringify(result));
    });
});

In previous versions, Collections where bound to the transaction where they were created.

Optimizations

  • Using new indexedDB methods getAll() & getAllKeys when available in IDBObjectStore & IDBIndex.
  • Faster promise implementation. Chaining .then() on returned promises will execute in a virtual micro-tick engine which ensures maximum performance as well as keeping indexedDB transactions alive no matter how long you chains are. Previous version did also keep indexedDB transaction alive, but executed then-handlers in a long and clumsy stack, which failed to comply fully with the A+ spec and made it cumbersome to debug and could theoretically end up in a stack overflow if utilizing very long promise chains.
  • No leaking arguments enables V8 to optimize more code.
  • No dynamic properties on Transaction objects.
  • Fewer layers when accessing a transaction.

Totally Rewritten Promise

The Promise class has been rewritten totally in order to be more optimized and execute all tasks in a virtual indexedDB-compliant microtick engine.

Cleaner Code

Dexie.js and its other modules has been revised and some complex methods has been simplified.

Architectural Changes

  • db.transaction() will now always execute the scope function asynchronically. In previous versions, the scope function could be executed either directly (synchronically) or asynchronically depending on whether the database was ready, or if a parent transaction was locked.
  • Table instances are singletons of WriteableTable now. There's no more need to dynamically generate Table instances when creating a transaction instance because the Table methods will inspect ongoing transaction runtime instead. A future major release (2.0) will likely deprecate WriteableTable and instead incorporate it into class Table, as with WriteableCollection to be incorporated into Collection. Table related properties on Transaction is subject of deprecation as well, since it's returned instances aren't bound to the transaction.

Other

See also pull request #242 which contains most of the changes in this release.

Known Issues

  • Open issues
  • Specifically, this version will trigger this zonejs issue when used together with karma-source-map-support. This is not a Dexie issue, but since Dexie v1.4.0 performs a feature detection by calling new Error().stack at startup, it will fail there if karma-source-map-support and zone.js are loaded.
Dexie.js - Dexie v1.4.0-rc.1

Published by dfahlander over 8 years ago

Probably the final pre-relase for 1.4.0. No new bugfixes or features added since the last beta. Just some build- and test improvements.

This rc was built using node 6 instead of node 4 that was used earlier.

Dexie.js - Dexie v1.4.0-beta.3

Published by dfahlander over 8 years ago

Fixed issue #248: 'modifications' object in 'updating' hook can be bizarre.

To install this pre-release from npm, use:

npm install dexie@next

or if you want to be more specific:

npm install [email protected]
Dexie.js - Dexie v1.4.0-beta2

Published by dfahlander over 8 years ago

Resolves issues #127 and #245. See also release notes for v1.4.0-beta.

Dexie.js - Dexie v1.4.0-beta

Published by dfahlander over 8 years ago

Optimized, simplified and debug friendlier.

This pre-relase contains an optimized and simplified code base that also is much easier to debug. Please help me test it out.

Long Stacks for Easier Debugging

  • Long stack support on all thrown errors in debug mode.
  • Debug mode is defined via Dexie.debug static property.
  • Dexie.debug will default to true when served from localhost.
Dexie.debug = true; // Enables long stacks (Default on when served from localhost)

db.friends.toArray(friends => {
    return friends.map(friend => friend.name);
}).then (names => {
    console.log(names.join(', ');
}).then (()=> {
    throw new Error ("oops!");
}).catch (function (e) {
    console.error ("Oops: " + e.stack); // Will see long stacks containing async flow:
         // Error: oops!
         //    at yourSource:file:line
         // From previous:
         //    at yourSource of prevous promise
         //    ...
         // From previous:
         //    at yourSrouce even earlier...
         //    ...
});

Totally Rewritten Promise

The Promise class has been rewritten totally in order to be more optimized and execute all tasks in a virtual microtick engine.

Promise.scheduler = customScheduler;

It is now possible to set a custom scheduler for Promise, like Bluebird's setScheduler(). The scheduler MUST be indexedDB friendly though. Maybe this could be something to use with angular to track digests and maintain scopes.


Dexie.Promise.scheduler = function customScheduler (callback, args) {
    $rootScope.$evalAsync(function() {
        callback.apply(null, args);
    });
};

I have not tested this with angular, so please help me test it. Setting a custom scheduler inactivates the internal virtual micro-tick engine and will always use the provided scheduler to call then-handlers in Promises. When using a custom scheduler, pay attention to whether indexedDB transaction survives your scheduler or not. setTimout() would not survive it. setImmediate() maybe.

Cleaner Code

Dexie.js and its other modules has been revised and some complex methods has been simplified.

Reusable Collections

If you prepare a collection:

var collection = db.friends.where('age').above(25);

...you can reuse that collection in any transaction later:

db.transaction('r', db.friends, function() {
    collection.toArray(function (result) {
        console.log(JSON.stringify(result));
    });
});

In previous versions, Collections where bound to the transaction where they were created.

Other

See also pull request #242 which contains most of the changes in this release.

Dexie.js - Dexie v1.3.6

Published by dfahlander over 8 years ago

News since v1.3.4

Features

  • WriteableTable.bulkPut();
  • WriteableTable.bulkDelete();
  • New options in Dexie constructor: indexedDB and IDBKeyRange. Makes it possible to specify a backing indexedDB implementation.
  • Support for WriteableTable.bulkAdd() for non-inbound primary keys (added second keys array argument)
  • Collection.raw() - inactivates 'reading' hooks for the collection. (Needed internally).
  • Collection.clone() - clone the collection to add additional filters without modifying existing collections.
  • Collection.filter() - alias to Collection.and().
  • Polyfilling 'versionchange' event on IE,Edge and Safari if happens in same window.

Optimization

  • Enormous optimization of WriteableCollection.delete() #208. Before it could take 30 seconds to delete 100,000 items. Now it takes just 300 ms on chrome and 3s on IE/Edge. 9ad20184a4f62fe8cc4fe0d544f82a77468a1c38, d539d18816beee8d2bf261f1433dc2fa2eaa369d,

Help Debugging

  • Unless overriden, Dexie will now console.warn() by default for the following events:
    • Promise.on('error') (unhandled promise rejection)
    • db.on('blocked') (other db connection blocks us from upgrading or deleting db)
    • db.on('versionchange') (other db connection wants to upgrade or delete db)
  • db.transaction() will now fail if returning a non-Dexie promise. 1214974e85674e505b12e1530e0d36a4958581dc

Quality Assurance

  • Rigorously unit testing CRUD hooks f9176fecf549c042dc9738d36ed96666688210de
  • eslint all Dexie modules.
  • Continous integration using travis and browserstack
  • In release script, unit tests run on various browsers. In this release, the following browsers were run:
    • Edge 13 on Windows 10
    • Firefox 45.0 on OS X El Capitan
    • Chrome 49 on OS X Mountain Lion

Fixes

  • Fixes in Error handling (DexieError and its sub classes) 21cdf2e06bc4a19208ee5d0eb6798f0127909821, b417aa360a645af4f09805a198219d2d1b882f28, c48e2e6ca35d20873c34e168ade01a0721e2f8d9.
  • In some situations, Promise.on('error') was signaled even when a promise was handled.
  • IEDeleteObjectStoreBug still present on Windows Edge Browser #205
  • Adding version to bower.json
  • Bugs in CRUD hooks API:
    • Bug in hooks handling of bulkAdd() found via tests and corrected (when using non-inbound keys)
    • Bug in hooks handling of put() found via tests and corrected (when using non-inbound keys)
    • Found bug in Table.add() when direct error is thrown, neither onerror or onsuccess called on the hook subscribers.
    • 64c83f21e0788b6c71540861da0c8c4a8921c22a
    • 214f21506acfa4a7c498cec4adda1dcb0f41111c
  • If using and() on a collection that is executed with .keys(), .eachKey() or .eachUniqueKey(), the argument passed to and() was undefined.
Dexie.js - Dexie v1.3.6-rc.1

Published by dfahlander over 8 years ago

News since v1.3.4

Features

  • WriteableTable.bulkPut();
  • WriteableTable.bulkDelete();
  • New options in Dexie constructor: indexedDB and IDBKeyRange. Makes it possible to specify a backing indexedDB implementation.
  • Support for WriteableTable.bulkAdd() for non-inbound primary keys (added second keys array argument)
  • Collection.raw() - inactivates 'reading' hooks for the collection. (Needed internally).
  • Collection.clone() - clone the collection to add additional filters without modifying existing collections.
  • Collection.filter() - alias to Collection.and().
  • Polyfilling 'versionchange' event on IE,Edge and Safari if happens in same window.

Optimization

  • Enormous optimization of WriteableCollection.delete() #208. Before it could take 30 seconds to delete 100,000 items. Now it takes just 300 ms on chrome and 3s on IE/Edge. 9ad20184a4f62fe8cc4fe0d544f82a77468a1c38, d539d18816beee8d2bf261f1433dc2fa2eaa369d,

Help Debugging

  • Unless overriden, Dexie will now console.warn() by default for the following events:
    • Promise.on('error') (unhandled promise rejection)
    • db.on('blocked') (other db connection blocks us from upgrading or deleting db)
    • db.on('versionchange') (other db connection wants to upgrade or delete db)
  • db.transaction() will now fail if returning a non-Dexie promise. 1214974e85674e505b12e1530e0d36a4958581dc

Quality Assurance

  • Rigorously unit testing CRUD hooks f9176fecf549c042dc9738d36ed96666688210de
  • eslint all Dexie modules.
  • Continous integration using travis and browserstack
  • In release script, unit tests run on various browsers. In this release, the following browsers were run:
    • Edge 13 on Windows 10
    • Firefox 45.0 on OS X El Capitan
    • Chrome 49 on OS X Mountain Lion

Fixes

  • Fixes in Error handling (DexieError and its sub classes) 21cdf2e06bc4a19208ee5d0eb6798f0127909821, b417aa360a645af4f09805a198219d2d1b882f28, c48e2e6ca35d20873c34e168ade01a0721e2f8d9.
  • In some situations, Promise.on('error') was signaled even when a promise was handled.
  • IEDeleteObjectStoreBug still present on Windows Edge Browser #205
  • Adding version to bower.json
  • Bugs in CRUD hooks API:
    • Bug in hooks handling of bulkAdd() found via tests and corrected (when using non-inbound keys)
    • Bug in hooks handling of put() found via tests and corrected (when using non-inbound keys)
    • Found bug in Table.add() when direct error is thrown, neither onerror or onsuccess called on the hook subscribers.
    • 64c83f21e0788b6c71540861da0c8c4a8921c22a
    • 214f21506acfa4a7c498cec4adda1dcb0f41111c
  • If using and() on a collection that is executed with .keys(), .eachKey() or .eachUniqueKey(), the argument passed to and() was undefined.
Dexie.js - Dexie v1.3.6-beta.3

Published by dfahlander over 8 years ago

Quality assurance:

  • Run eslint on all code and enforce eslint passing in release script
  • Launch unit tests on browserstack d9228dc in release script. Currently just Chrome, Firefox and Edge. Will add more devices and browsers later.
  • Code review and some actions taken b29ec59:
    • Separating extend() into extendProto() and extend() (different use cases).
    • db-classes (Collection, Table etc) now have non-enumerable methods now on their prototype.
    • New method dump() on errors derived from DexieError. Returns string. To be used instead of (e.stack || e). It will dump name, message and stack. Like 'stack' on chrome but also for Firefox.
    • Static method Dexie.dump(error). Works as DexieError.dump().
    • Promise default uncaught handler: console.warn() instead of console.error().
    • Typescript definitions updates.
Dexie.js - Dexie v1.3.6-beta.2

Published by dfahlander over 8 years ago

  • Bug in bulkPut() when using CRUD hook and mixing updates and creation ed19e64
  • eslint corrections + moved 'stack' method between modules. 2d42749
  • Throw if not using Dexie.Promise from transaction scopes. … 1214974
Dexie.js - Dexie v1.3.6-beta.1

Published by dfahlander over 8 years ago

Several improvements and bugfixes:

  • Big optimization of WriteableCollection.delete() (this time it DOESN'T crash IE or Edge!)
  • Support for bulkPut() and bulkDelete().
  • New methods on Collection: Collection.raw() and Collection.clone()
  • Default console.warn() when db upgrade or deletion was blocked (overridable)
  • Rigorous unit testing of CRUD hook api. Found and corrected several bugs.
  • Updated typings with added methods.

Production release will come within couple of days...

Dexie.js - Dexie v1.3.5-beta.2

Published by dfahlander over 8 years ago

  • #208 Optimization of WriteableCollection.delete()
  • Feature: Possible to provide the indexedDB and IDBKeyRange implementation in Dexie constructor (using options.indexedDB and options.IDBKeyRange).
  • Bugfix in DexieError subclasses - didnt set inner property. b417aa360a645af4f09805a198219d2d1b882f28
  • Bugfix: Promises never return on node (when MissingAPIError was thrown)
  • By default, log to console.error if any Promise was uncaught https://github.com/dfahlander/Dexie.js/pull/206
  • False alarms in Promise.on('error') (also explained in https://github.com/dfahlander/Dexie.js/pull/206)
  • Bugfix:
    IEDeleteObjectStoreBug still present on Windows Edge Browser #205
Dexie.js - Dexie v1.3.5-beta

Published by dfahlander over 8 years ago

  • Feature: Possible to provide the indexedDB and IDBKeyRange implementation in Dexie constructor (using options.indexedDB and options.IDBKeyRange).
  • Bugfix in DexieError subclasses - didnt set inner property. b417aa360a645af4f09805a198219d2d1b882f28
  • Bugfix: Promises never return on node (when MissingAPIError was thrown)
  • By default, log to console.error if any Promise was uncaught https://github.com/dfahlander/Dexie.js/pull/206
  • False alarms in Promise.on('error') (also explained in https://github.com/dfahlander/Dexie.js/pull/206)
  • Bugfix:
    IEDeleteObjectStoreBug still present on Windows Edge Browser #205
Dexie.js - Dexie v1.3.4

Published by dfahlander over 8 years ago

Bugfixes

  • dexie seems to be published as an ES6 module on JSPM #195
  • Including built addons for dexie's bower package (Bower install for addons #185)
  • Missing stacks on exceptions
  • bulkAdd() support on non-inbound tables if primKey is auto incremented (#90)
  • SecurityError when storage is disabled #158
  • Removed the "typescript/definitions" element of package.json (commit 0eaec3bf223ab8be9c92a2ac18aebade1fb028d8)
  • Typescript definitions should now cover the entire public API and is a little smarter.
  • Bugfix in typescript sample (commit 4038135330912322a0f194ab7e4d75acac61353f)
  • addons have peerDependencies instead of dependencies.

Development environment

  • "build" renamed to "tools".
  • Include src, build and test in npm- and bower packages (can be nice to be able to see or lab with the code without having to fork and clone. Also, I believe it is more conventional to point jsnext:main to src, not dist)
  • Include addons in bower packages (not npm, because they have their own npm packages)
  • Removed es6 output from dist and instead point jsnext:main to src/Dexie.js
  • Refactored Dexie.js some more - extracted more classes and functions.
  • Unit tests can utilize "spawnedTest" instead of "asyncTest" for prettier code using yield.

Minor changes:

  • Renamed class Dexie.events to Dexie.Events (backward compatible though!)
  • Dexie.errnames changed (commit d24b098728d4cfb8af3f62684aa27eba548a32fa)
  • Support for arrow functions in modify (9e9ae0515308d5b771759d630de20bd06737e524)
Dexie.js - Dexie v1.3.3

Published by dfahlander over 8 years ago

News:

  • DexieError and sub exception classes - improved exception handling #189. All errors coming out from Dexie will now be of different types
  • New option in Dexie constructor: autoOpen: false new Dexie("name", {autoOpen: false})
  • Fixed fault in jspm support (jspm didnt detect dexie.es6.js as es6 module)
  • Fix for falsy keys in put() and add() #175 when there are CRUD hooks going on.
  • Updated dexie.d.ts with bulkAdd() method.
  • README updates
Dexie.js - Dexie v1.3.0

Published by dfahlander over 8 years ago

Dexie v1.3.0 was at last released, six months after the previous release, 1.2.0. There are a lot of news, check out!

New features

  • New WhereClause methods

    anyOfIgnoreCase()
    inAnyRange()
    startsWithAnyOfIgnoreCase()

  • Improved WhereClause methods:

    noneOf() Supports large array as argument
    notEqual() More efficient

  • Support for using yield (as await)

  • New method for improved performance when adding thousands of items into a table:

    bulkAdd()

  • Updated Typescript definition.

    Module based instead of global.
    Supports latest typescript compiler.
    typings attribute in package.json eliminates the need of DefinitelyTyped and tsd.
    "typescript.definitions"attribute in package.json makes tsd detect the typings in github.

  • Support for the new standard module format "es6" (separate output).

File Structure Update

  • The files in the dist directory has been moved. dist/latestis removed and files are put directly under dist and are all in lowercase.

  • Dist files are removed from the master branch. They are only checked in by the release.sh script in the releases branch so that each release will have them (so that our bower users get happy).

  • Addons are no more part of the npm package (or bower package). They are also ES6 based and have their own build system. They are released separately as their own npm modules

    npm install dexie-observable --save
    npm install dexie-syncable --save
    
  • Bower users can also install the npm modules through:

    bower install https://npmcdn.com/dexie-observable@SEMVER/bower.zip
    bower install https://npmcdn.com/dexie-syncable@SEMVER/bower.zip
    

    ...where SEMVER is a version query in semver format, such as 0.1.x, ~0.1.2, ^0.1.3 etc.

Bugfixes

Wow, there's been a lot of small little fixes. 6 months are hard to conclude here. Read the commit log to see the details.

Build-, Test and Release system

Introduced scripts for building, testing and releasing Dexie.js. Source code is migrated to the ES6 module format as a base for further refactoring of Dexie.js into separate modules. Now, to contribute to Dexie.js you will need to:

npm install
npm run build or npm run watch

And to test in command line (thanks to @YuriSolovyov)
npm test

There's a little guide in README#Contributing on how to use npm link to symlink you github clone to your app's node_modules/dexie, which works perfectly well on windows systems as well.

Dexie.js - Dexie v1.3.2

Published by dfahlander over 8 years ago

Features:

  • Support for option {autoOpen: false} in Dexie constructor.

Fixes:

  • bower install for addons
  • Issue with Typescript and Dexie #186,#188
  • Explicit support for jspm in package.json

For all the details, see https://github.com/dfahlander/Dexie.js/commits/master

Dexie.js - Dexie v1.3.1

Published by dfahlander over 8 years ago

This release only have some README.md typo fixes since v1.3.0. See release notes for 1.3.0.

Dexie.js - Dexie v1.2.0

Published by dfahlander about 9 years ago

New Features

API Changes

  • Resolving db.open() with the db instance instead of undefined: Pull request #129, commit 01032444965f93a362d5b4961dcb371381f4584f

Solved Issues

  • Issue #125 Can't properly require with requirejs. Solved in pull Request #126 Do not define name for require.js
  • Issue #113 Can't define class when table with composite key
  • Issue #78 Workaround for chrome bug: Transaction promise never completes on low disk space in chrome apps
  • Issue #134 Safari Private Browsing
  • Issue #114 mapToClass() prototype mess ...
  • Issue #123 Mini bug on line 70 Full Text Search 2 Sample