Designing an IndexedDB schema for a multi-user offline note-taking app requires a structure that supports: Multiple users Multiple notes per user Sync and status tracking Efficient querying (e.g., by user, tags, sync state) Recommended Object Store Schema We’ll define three object stores : 1. users – Stores basic user info 2. notes – Stores each note 3. tags (optional) – For global tagging/filters Object Store Design Store Name Key Path Indexes Purpose users id email (unique) Auth, ownership notes id userId , updatedAt , synced Note lookup, syncing, sorting tags name none Optional visual tagging Schema Setup (in onupgradeneeded ) Sync Support Example To support sync with a server: Use a synced flag ( true/false ) Use updatedAt timestamp for conflict resolution Optionally include isDeleted for soft-deletes Example Queries Query How to Perform Get all notes for user X notes.index(\"userId\").getAll(\"user123\") Get unsynced notes notes.index(\"synced\").getAll(false) Get notes updated after a date Use IDBKeyRange.lowerBound(timestamp) Sort notes by update time Use updatedAt index with cursor Extra Considerations Feature Suggestion Encryption Use Web Crypto API for secure note content Data expiration Add lastOpenedAt and prune unused accounts Multi-device sync Store a remoteId or rev to map local-to-server sync Conflict resolution Track updatedAt , userId , and deviceId if needed Final Tip Wrap all IndexedDB operations in a Promise -based helper or use a library like: idb Dexie.js
Designing an IndexedDB schema for a multi-user offline note-taking app requires a structure that supports:
Recommended Object Store Schema
We’ll define three object stores:
1.
users– Stores basic user info2.
notes– Stores each note3.
tags(optional) – For global tagging/filtersObject Store Design
usersidemail(unique)notesiduserId,updatedAt,syncedtagsnameSchema Setup (in
onupgradeneeded)Sync Support Example
To support sync with a server:
syncedflag (true/false)updatedAttimestamp for conflict resolutionisDeletedfor soft-deletesExample Queries
Xnotes.index("userId").getAll("user123")notes.index("synced").getAll(false)IDBKeyRange.lowerBound(timestamp)updatedAtindex with cursorExtra Considerations
lastOpenedAtand prune unused accountsremoteIdorrevto map local-to-server syncupdatedAt,userId, anddeviceIdif neededFinal Tip
Wrap all IndexedDB operations in a
Promise-based helper or use a library like:idbDexie.js