https://github.com/rahuldhole/idbsuit
IndexedDB Suit for handling migrations and data models
https://github.com/rahuldhole/idbsuit
database indexeddb offline-first pwa
Last synced: 4 months ago
JSON representation
IndexedDB Suit for handling migrations and data models
- Host: GitHub
- URL: https://github.com/rahuldhole/idbsuit
- Owner: rahuldhole
- License: apache-2.0
- Created: 2024-05-14T13:53:55.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-06-12T06:52:30.000Z (about 1 year ago)
- Last Synced: 2025-09-18T21:49:48.109Z (10 months ago)
- Topics: database, indexeddb, offline-first, pwa
- Language: Dockerfile
- Homepage:
- Size: 203 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# IDBSuit
[](https://badge.fury.io/js/idbsuit) [](https://github.com/rahuldhole/IDBSuit/blob/main/LICENSE)

IndexedDB Suit for handling migrations automatically and provide ORM.
Sample react project: https://github.com/rahuldhole/slick-pick
In your config directory create `IDBSuit.js` and update path to your `./migrations` folder and `Schema.js`
Note: In IndexedDB all migrations are irreversible. If you need to reverse an immigration you may need to create another migration file
```
// IDBSuit.js
import { IDBS } from 'idbsuit'; // package
// Change your Schema.js path
import { Schema } from './Schema';
// change your migrations/ folder path
const reqMigrations = require.context('./migrations', true, /\.js$/);
const migrationModules = reqMigrations.keys().map(key => reqMigrations(key));
export default function IDBSuit() {
const idbs = new IDBS(Schema, migrationModules);
return idbs;
}
```
Create IDBSute object.
```
const idbs = IDBSuit();
```
Open connection to your db
```
idbs.openDatabase()
.then(dbInstance => {
setDbVersion(dbInstance.version);
})
.catch(error => {
console.error('Error opening database:', error);
});
```
Destroy db
```
idbs.destroy()
.then(() => {
console.log('Database deleted successfully');
})
.catch(error => {
console.error('Error deleting database:', error);
});
```
## Migration
Make sure to always use increamental version number.
Recommended to use current timestamp integer `new Date().getTime()` as version number.
Similarly, you may prefix your migration file with version although it is not neccessary but it may help in visibility.
```
import { Migration } from "idbsuit";
export default class ExampleOne extends Migration{
static #_= this.newVersion(1714815400413); // update version number
async migrate() {
return new Promise((resolve, reject) => {
// Implement your migration logic here
resolve();
});
}
}
```