What is dexie?
Dexie is a wrapper for IndexedDB, a low-level API for client-side storage of significant amounts of structured data, including files/blobs. Dexie simplifies the use of IndexedDB by providing a more developer-friendly API and additional features such as versioning, transactions, and observability.
What are dexie's main functionalities?
Database Initialization
This code initializes a new Dexie database named 'MyDatabase' and defines a schema for a 'friends' table with auto-incrementing primary key 'id' and indexed fields 'name' and 'age'.
const db = new Dexie('MyDatabase');
db.version(1).stores({
friends: '++id,name,age'
});
Adding Data
This code adds a new record to the 'friends' table with the name 'John' and age 25.
db.friends.add({name: 'John', age: 25});
Querying Data
This code queries the 'friends' table for all records where the age is below 30 and logs the results to the console.
db.friends.where('age').below(30).toArray().then(friends => {
console.log(friends);
});
Updating Data
This code updates the record with primary key 1 in the 'friends' table, setting the age to 26.
db.friends.update(1, {age: 26});
Deleting Data
This code deletes the record with primary key 1 from the 'friends' table.
db.friends.delete(1);
Other packages similar to dexie
idb
The 'idb' package is a small library that provides a more modern and promise-based API for IndexedDB. It is simpler and lighter than Dexie but does not offer as many advanced features such as observability and complex querying.
localforage
LocalForage is a library that provides a simple API for storing data in various storage backends, including IndexedDB, WebSQL, and localStorage. It is more versatile in terms of storage options but does not offer the same level of IndexedDB-specific features and optimizations as Dexie.
pouchdb
PouchDB is a JavaScript database that syncs with CouchDB. It provides a more comprehensive solution for offline-first applications with synchronization capabilities. However, it is heavier and more complex compared to Dexie, which is focused solely on IndexedDB.
Dexie.js
A bullet proof indexedDB wrapper.
- Minimalistic and straight forward API, easy to use.
- Code Completion friendly - Your IDE will guide you as you type!
- Human readable queries: db.friends.where("lastName").anyOf("Helenius", "Fahlander").each(function(friend){...})
- Bullet proof error handling using transaction scopes
- The only indexedDB wrapper (so far) to support case insensitive search, set matching and logical OR operations.
- Promise/A+ compliant
- Does not hide backend indexedDB from the caller - always possible to reach the backend IDB objects.
- Performance focused
- Portable across all browsers:
- IE10+
- Chrome
- Firefox
- Opera 15+
- Android browser
- Blackberry browser
- Opera mobile 16+
- Chrome for Android
- Firefox for Android
- IE Mobile
- Safari 8
- IOS Safari 8
- Extended key range queries: equalsIgnoreCase(), anyOf([a,b,c,d,...]), startsWith(), startsWithIgnoreCase()
- Logical "OR": friends.where("age").below(40).or("length").above(200).toArray(...);
- Built to be easily extended and build addons upon.
- Simplified and robust error handling
- Simplified upgrading framework
- Thoroughly unit tested
Documentation
https://github.com/dfahlander/Dexie.js/wiki/Dexie.js
Samples
https://github.com/dfahlander/Dexie.js/wiki/Samples
Forum
https://groups.google.com/forum/#!forum/dexiejs
Download
https://raw.githubusercontent.com/dfahlander/Dexie.js/master/dist/latest/Dexie.js
https://raw.githubusercontent.com/dfahlander/Dexie.js/master/dist/latest/Dexie.min.js