You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

121 lines
3.3 KiB

/**
* 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
};