feat(android): implement Phase 1.1 SQLite database sharing with WAL mode
- Add DailyNotificationDatabase.java with three-table schema and WAL configuration - Add DailyNotificationMigration.java for SharedPreferences to SQLite migration - Add DailyNotificationDatabaseTest.java with comprehensive unit tests - Add ConfigureOptions interface with dbPath, storage mode, and TTL settings - Add configure() method to DailyNotificationPlugin interface - Update Android plugin with SQLite integration and automatic migration - Update web implementations to implement new configure() method - Add phase1-sqlite-usage.ts example demonstrating shared storage configuration This implements the critical Phase 1.1 gate for shared SQLite storage: - App and plugin can open the same SQLite file with WAL mode - Automatic migration from SharedPreferences preserves existing data - Schema version checking prevents compatibility issues - Concurrent reads during background writes enabled - Configuration API supports both shared and tiered storage modes Files: 8 changed, 1204 insertions(+)
This commit is contained in:
121
examples/phase1-sqlite-usage.ts
Normal file
121
examples/phase1-sqlite-usage.ts
Normal file
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* Phase 1.1 Usage Example
|
||||
*
|
||||
* Demonstrates SQLite database sharing configuration and usage
|
||||
* Shows how to configure the plugin for shared storage mode
|
||||
*
|
||||
* @author Matthew Raymer
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
import { DailyNotification } from '@timesafari/daily-notification-plugin';
|
||||
|
||||
/**
|
||||
* Example: Configure plugin for shared SQLite storage
|
||||
*/
|
||||
async function configureSharedStorage() {
|
||||
try {
|
||||
console.log('Configuring plugin for shared SQLite storage...');
|
||||
|
||||
// Configure the plugin with shared storage mode
|
||||
await DailyNotification.configure({
|
||||
dbPath: '/data/data/com.yourapp/databases/daily_notifications.db',
|
||||
storage: 'shared',
|
||||
ttlSeconds: 3600, // 1 hour TTL
|
||||
prefetchLeadMinutes: 15, // 15 minutes before notification
|
||||
maxNotificationsPerDay: 5,
|
||||
retentionDays: 7
|
||||
});
|
||||
|
||||
console.log('✅ Plugin configured successfully for shared storage');
|
||||
|
||||
// Now the plugin will use SQLite database instead of SharedPreferences
|
||||
// The database will be shared between app and plugin
|
||||
// WAL mode enables concurrent reads during writes
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Configuration failed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Example: Configure plugin for tiered storage (current implementation)
|
||||
*/
|
||||
async function configureTieredStorage() {
|
||||
try {
|
||||
console.log('Configuring plugin for tiered storage...');
|
||||
|
||||
// Configure the plugin with tiered storage mode (default)
|
||||
await DailyNotification.configure({
|
||||
storage: 'tiered',
|
||||
ttlSeconds: 1800, // 30 minutes TTL
|
||||
prefetchLeadMinutes: 10, // 10 minutes before notification
|
||||
maxNotificationsPerDay: 3,
|
||||
retentionDays: 5
|
||||
});
|
||||
|
||||
console.log('✅ Plugin configured successfully for tiered storage');
|
||||
|
||||
// Plugin will continue using SharedPreferences + in-memory cache
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Configuration failed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Example: Schedule notification with new configuration
|
||||
*/
|
||||
async function scheduleWithNewConfig() {
|
||||
try {
|
||||
// First configure for shared storage
|
||||
await configureSharedStorage();
|
||||
|
||||
// Then schedule a notification
|
||||
await DailyNotification.scheduleDailyNotification({
|
||||
url: 'https://api.example.com/daily-content',
|
||||
time: '09:00',
|
||||
title: 'Daily Update',
|
||||
body: 'Your daily notification is ready',
|
||||
sound: true,
|
||||
priority: 'high'
|
||||
});
|
||||
|
||||
console.log('✅ Notification scheduled with shared storage configuration');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Scheduling failed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Example: Check migration status
|
||||
*/
|
||||
async function checkMigrationStatus() {
|
||||
try {
|
||||
// Configure for shared storage to trigger migration
|
||||
await DailyNotification.configure({
|
||||
storage: 'shared',
|
||||
dbPath: '/data/data/com.yourapp/databases/daily_notifications.db'
|
||||
});
|
||||
|
||||
// The plugin will automatically:
|
||||
// 1. Create SQLite database with WAL mode
|
||||
// 2. Migrate existing SharedPreferences data
|
||||
// 3. Validate migration success
|
||||
// 4. Log migration statistics
|
||||
|
||||
console.log('✅ Migration completed automatically during configuration');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Migration failed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Export examples for use
|
||||
export {
|
||||
configureSharedStorage,
|
||||
configureTieredStorage,
|
||||
scheduleWithNewConfig,
|
||||
checkMigrationStatus
|
||||
};
|
||||
Reference in New Issue
Block a user