The Database API provides methods for storing and retrieving memories, user settings, and analytics data using IndexedDB with Dexie.
- id: Primary key (auto-increment)
- title: String - Memory title
- content: String - Memory content
- category: String - Category classification
- tags: Array - Associated tags
- isFavorite: Boolean - Favorite status
- createdAt: Date - Creation timestamp
- updatedAt: Date - Last modification timestamp
- aiSummary: String - AI-generated summary
- aiTags: Array - AI-suggested tags
- templateId: String - Associated template ID
- collectionIds: Array - Smart collection IDs
- key: Primary key (String)
- value: Any - Setting value
- id: Primary key (auto-increment)
- event: String - Event type
- timestamp: Date - Event timestamp
- metadata: Object - Additional event data
Adds a new memory to the database.
Parameters:
memory(Object): Memory object containing title, content, category, tags, etc.
Returns:
- Promise resolving to the created memory with assigned ID
Example:
const memory = await addMemory({
title: "Important Meeting",
content: "Discussed project timeline and deliverables",
category: "Work",
tags: ["meeting", "project"],
isFavorite: false
});Retrieves all memories from the database.
Returns:
- Promise resolving to array of all memories
Retrieves a specific memory by ID.
Parameters:
id(Number): Memory ID
Returns:
- Promise resolving to memory object or undefined
Updates an existing memory.
Parameters:
id(Number): Memory IDupdates(Object): Fields to update
Returns:
- Promise resolving to updated memory count
Deletes a memory by ID.
Parameters:
id(Number): Memory ID
Returns:
- Promise resolving to deletion count
Retrieves a setting value by key.
Parameters:
key(String): Setting key
Returns:
- Promise resolving to setting value or undefined
Sets a setting value.
Parameters:
key(String): Setting keyvalue(Any): Setting value
Returns:
- Promise resolving to setting object
Records an analytics event.
Parameters:
event(String): Event typemetadata(Object): Additional event data
Returns:
- Promise resolving to created analytics record
Retrieves all analytics data.
Returns:
- Promise resolving to array of analytics records
Generates analytics summary with key metrics.
Returns:
- Promise resolving to analytics summary object
Performs full-text search on memories.
Parameters:
query(String): Search query
Returns:
- Promise resolving to array of matching memories
Retrieves memories by category.
Parameters:
category(String): Category name
Returns:
- Promise resolving to array of memories in category
Retrieves memories by tag.
Parameters:
tag(String): Tag name
Returns:
- Promise resolving to array of memories with tag
Retrieves all favorite memories.
Returns:
- Promise resolving to array of favorite memories
The database is automatically initialized when the module is imported. It creates the necessary tables and indexes for optimal performance.
All database operations return promises and should be wrapped in try-catch blocks for proper error handling:
try {
const memory = await addMemory(memoryData);
console.log('Memory created:', memory);
} catch (error) {
console.error('Failed to create memory:', error);
}The database schema is versioned and will automatically migrate when the structure changes. Data integrity is maintained during migrations.