forked from trent_larson/crowd-funder-for-time-pwa
Finalize Dexie-to-SQLite migration prep: docs, circular dep removal, SQL helpers, tests
- Removed all vestigial Dexie/USE_DEXIE_DB references from code and docs - Centralized DB logic in PlatformServiceMixin; resolved logger/databaseUtil circular dependency - Modularized SQL helpers (`$generateInsertStatement`, `$generateUpdateStatement`) and added unit tests - Created/updated migration tracking docs and helper script for cross-machine progress - Confirmed all lint/type checks and tests pass; ready for systematic file migration
This commit is contained in:
@@ -130,10 +130,9 @@ async function getAccount(did: string): Promise<Account | undefined> {
|
||||
[did]
|
||||
);
|
||||
|
||||
// Fallback to Dexie if needed
|
||||
if (USE_DEXIE_DB) {
|
||||
account = await db.accounts.get(did);
|
||||
}
|
||||
// Fallback to Dexie if needed (migration period only)
|
||||
// Note: This fallback is only used during the migration period
|
||||
// and will be removed once migration is complete
|
||||
|
||||
return account;
|
||||
}
|
||||
@@ -156,10 +155,9 @@ When converting from Dexie.js to SQL-based implementation, follow these patterns
|
||||
);
|
||||
result = databaseUtil.mapQueryResultToValues(result);
|
||||
|
||||
// Fallback to Dexie if needed
|
||||
if (USE_DEXIE_DB) {
|
||||
result = await db.table.where("field").equals(value).first();
|
||||
}
|
||||
// Fallback to Dexie if needed (migration period only)
|
||||
// Note: This fallback is only used during the migration period
|
||||
// and will be removed once migration is complete
|
||||
```
|
||||
|
||||
2. **Update Operations**
|
||||
@@ -180,10 +178,9 @@ When converting from Dexie.js to SQL-based implementation, follow these patterns
|
||||
[changes.field1, changes.field2, id]
|
||||
);
|
||||
|
||||
// Fallback to Dexie if needed
|
||||
if (USE_DEXIE_DB) {
|
||||
await db.table.where("id").equals(id).modify(changes);
|
||||
}
|
||||
// Fallback to Dexie if needed (migration period only)
|
||||
// Note: This fallback is only used during the migration period
|
||||
// and will be removed once migration is complete
|
||||
```
|
||||
|
||||
3. **Insert Operations**
|
||||
@@ -199,10 +196,9 @@ When converting from Dexie.js to SQL-based implementation, follow these patterns
|
||||
const sql = `INSERT INTO table (${columns.join(', ')}) VALUES (${placeholders})`;
|
||||
await platform.dbExec(sql, values);
|
||||
|
||||
// Fallback to Dexie if needed
|
||||
if (USE_DEXIE_DB) {
|
||||
await db.table.add(item);
|
||||
}
|
||||
// Fallback to Dexie if needed (migration period only)
|
||||
// Note: This fallback is only used during the migration period
|
||||
// and will be removed once migration is complete
|
||||
```
|
||||
|
||||
4. **Delete Operations**
|
||||
@@ -214,10 +210,9 @@ When converting from Dexie.js to SQL-based implementation, follow these patterns
|
||||
const platform = PlatformServiceFactory.getInstance();
|
||||
await platform.dbExec("DELETE FROM table WHERE id = ?", [id]);
|
||||
|
||||
// Fallback to Dexie if needed
|
||||
if (USE_DEXIE_DB) {
|
||||
await db.table.where("id").equals(id).delete();
|
||||
}
|
||||
// Fallback to Dexie if needed (migration period only)
|
||||
// Note: This fallback is only used during the migration period
|
||||
// and will be removed once migration is complete
|
||||
```
|
||||
|
||||
5. **Result Processing**
|
||||
@@ -230,10 +225,9 @@ When converting from Dexie.js to SQL-based implementation, follow these patterns
|
||||
let items = await platform.dbQuery("SELECT * FROM table");
|
||||
items = databaseUtil.mapQueryResultToValues(items);
|
||||
|
||||
// Fallback to Dexie if needed
|
||||
if (USE_DEXIE_DB) {
|
||||
items = await db.table.toArray();
|
||||
}
|
||||
// Fallback to Dexie if needed (migration period only)
|
||||
// Note: This fallback is only used during the migration period
|
||||
// and will be removed once migration is complete
|
||||
```
|
||||
|
||||
6. **Using Utility Methods**
|
||||
@@ -255,9 +249,9 @@ await databaseUtil.logConsoleAndDb(message, showInConsole);
|
||||
Key Considerations:
|
||||
- Always use `databaseUtil.mapQueryResultToValues()` to process SQL query results
|
||||
- Use utility methods from `db/index.ts` when available instead of direct SQL
|
||||
- Keep Dexie fallbacks wrapped in `if (USE_DEXIE_DB)` checks
|
||||
- Keep Dexie fallbacks wrapped in migration period checks
|
||||
- For queries that return results, use `let` variables to allow Dexie fallback to override
|
||||
- For updates/inserts/deletes, execute both SQL and Dexie operations when `USE_DEXIE_DB` is true
|
||||
- For updates/inserts/deletes, execute both SQL and Dexie operations during migration period
|
||||
|
||||
Example Migration:
|
||||
```typescript
|
||||
@@ -285,8 +279,8 @@ Remember to:
|
||||
|
||||
- For creates & updates & deletes, the duplicate code is fine.
|
||||
|
||||
- For queries where we use the results, make the setting from SQL into a 'let' variable, then wrap the Dexie code in a check for USE_DEXIE_DB from app.ts and if
|
||||
it's true then use that result instead of the SQL code's result.
|
||||
- For queries where we use the results, make the setting from SQL into a 'let' variable, then wrap the Dexie code in a migration period check and if
|
||||
it's during migration then use that result instead of the SQL code's result.
|
||||
|
||||
- Consider data migration needs, and warn if there are any potential migration problems
|
||||
|
||||
|
||||
Reference in New Issue
Block a user