IDB - Memorio
🖥️ Browser Only: Requires IndexedDB (not available in Node.js/Deno)
IDB provides access to browser IndexedDB for large data storage. Unlike localStorage, IDB can store large amounts of structured data.
Installation
npm install memorio
import 'memorio';
Quick Examples
Example 1: Basic Usage
// Create a database
idb.db.create('myApp');
// Add data
idb.data.set('myApp', 'users', { id: 1, name: 'Mario' });
// Get data
const user = idb.data.get('myApp', 'users', 1);
console.log(user.name); // "Mario"
Example 2: Intermediate
// Create database with tables
idb.db.create('store');
idb.table.create('store', 'products');
// Add multiple records
idb.data.set('store', 'products', { id: 1, name: 'Apple', price: 1.5 });
idb.data.set('store', 'products', { id: 2, name: 'Banana', price: 0.8 });
// List databases
const databases = idb.db.list();
console.log(databases); // ['myApp', 'store']
Example 3: Advanced
// Check database support
if (idb.db.support()) {
// Use IDB
}
// Get database info
const version = idb.db.version('store');
const size = idb.db.size('store');
// Delete database
idb.db.delete('store');
// Handle quota
const quota = idb.db.quota();
console.log(`Using ${quota.used} of ${quota.total} bytes`);
API Reference
Database Methods
| Method | Parameters | Returns | Description |
|---|---|---|---|
idb.db.create(name) |
name: string |
void |
Create database |
idb.db.delete(name) |
name: string |
void |
Delete database |
idb.db.list() |
none | string[] |
List all databases |
idb.db.exist(name) |
name: string |
boolean |
Check if exists |
idb.db.size(name) |
name: string |
number |
Get database size |
idb.db.version(name) |
name: string |
number |
Get version |
idb.db.support() |
none | boolean |
Check browser support |
idb.db.quota() |
none | object |
Get storage quota |
Table Methods
| Method | Parameters | Returns | Description |
|---|---|---|---|
idb.table.create(db, table) |
db: string, table: string |
void |
Create table |
idb.table.size(db, table) |
db: string, table: string |
number |
Get table size |
Data Methods
| Method | Parameters | Returns | Description |
|---|---|---|---|
idb.data.get(db, table, id) |
db, table, id |
any |
Get single record |
idb.data.set(db, table, data) |
db, table, data |
void |
Set record |
idb.data.delete(db, table, id) |
db, table, id |
void |
Delete record |
Data Structure
Each record needs an id field:
idb.data.set('myDB', 'users', {
id: 1, // Required!
name: 'Mario',
email: 'm@test.com'
});
Platform Support
| Platform | Support | Notes |
|---|---|---|
| Browser | ✅ Full | Full IndexedDB support |
| Edge Worker | ⚠️ Limited | May not be available in all workers |
| Node.js | ❌ Not available | Use store or session instead |
| Deno | ❌ Not available | Use store or session instead |
Storage Limits
- Desktop browsers: 50+ MB (often unlimited)
- Mobile browsers: 50-100 MB
- More than localStorage: Much higher limits
Best Practices
- Always include
idin records - Use for large data: images, caches, offline data
- Check support:
idb.db.support() - Clean up:
idb.db.delete('tempDB')
Use Cases
Offline Data
// Cache API response
idb.data.set('cache', 'apiResponse', {
id: 'users',
data: usersArray,
timestamp: Date.now()
});
Large User Data
// Store user-generated content
idb.data.set('app', 'uploads', {
id: Date.now(),
file: fileData,
userId: currentUser.id
});
Disclaimer
All content on this website, including text and images, has been generated using artificial intelligence technologies. While every effort is made to ensure quality and coherence, I do not assume responsibility for any inaccuracies, errors, or interpretations resulting from the use of this material.
Copyright and Intellectual property
All content on this website is copyrighted. Any copying, reproduction, distribution, or use of materials in any form is strictly forbidden without prior written permission. Violations will be subject to legal action in accordance with copyright law. We appreciate your understanding and compliance.
All content on this website, including text and images, has been generated using artificial intelligence technologies. While every effort is made to ensure quality and coherence, I do not assume responsibility for any inaccuracies, errors, or interpretations resulting from the use of this material.
Copyright and Intellectual property
All content on this website is copyrighted. Any copying, reproduction, distribution, or use of materials in any form is strictly forbidden without prior written permission. Violations will be subject to legal action in accordance with copyright law. We appreciate your understanding and compliance.