refactor(database): migrate to new modular database layer and unify data access
- Remove legacy database.ts, LocalDataSource.ts, and MessageRepository.ts - Create new src/database/ module with messageRepository, userCacheRepository, conversationRepository, and groupCacheRepository - Update all consumers to import from @/database instead of services/database - Add web platform blur handling for modal components to fix focus issues - Flatten SystemMessageItem and NotificationsScreen styles for consistent design - Add draggable slider in ChatSettingsScreen and dynamic font size support - Introduce 9 new chat color themes - Add profile screens for about, terms, and privacy policy with navigation routes - Add policy links to login and registration screens - Fix post share URL format from /posts/ to /post/
This commit is contained in:
54
src/database/index.ts
Normal file
54
src/database/index.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { localDataSource } from './LocalDataSource';
|
||||
import { databaseManager } from './core/DatabaseManager';
|
||||
|
||||
export { databaseManager } from './core/DatabaseManager';
|
||||
export { DatabaseManager } from './core/DatabaseManager';
|
||||
export { localDataSource, LocalDataSource } from './LocalDataSource';
|
||||
|
||||
export {
|
||||
messageRepository, MessageRepository,
|
||||
conversationRepository, ConversationRepository,
|
||||
userCacheRepository, UserCacheRepository,
|
||||
groupCacheRepository, GroupCacheRepository,
|
||||
postCacheRepository, PostCacheRepository,
|
||||
} from './repositories';
|
||||
|
||||
export { CachedMessage } from './types';
|
||||
|
||||
export async function clearAllData(): Promise<void> {
|
||||
await localDataSource.enqueueWrite(async () => {
|
||||
await localDataSource.execute(`DELETE FROM messages`);
|
||||
await localDataSource.execute(`DELETE FROM conversations`);
|
||||
await localDataSource.execute(`DELETE FROM conversation_cache`);
|
||||
await localDataSource.execute(`DELETE FROM conversation_list_cache`);
|
||||
await localDataSource.execute(`DELETE FROM users`);
|
||||
await localDataSource.execute(`DELETE FROM current_user_cache`);
|
||||
await localDataSource.execute(`DELETE FROM groups`);
|
||||
await localDataSource.execute(`DELETE FROM group_members`);
|
||||
await localDataSource.execute(`DELETE FROM posts_cache`);
|
||||
});
|
||||
}
|
||||
|
||||
export const initDatabase = async (userId?: string | null): Promise<void> => {
|
||||
await databaseManager.initialize(userId);
|
||||
};
|
||||
|
||||
export const closeDatabase = async (): Promise<void> => {
|
||||
await databaseManager.close();
|
||||
};
|
||||
|
||||
export const getCurrentDbUserId = (): string | null => {
|
||||
return databaseManager.getCurrentUserId();
|
||||
};
|
||||
|
||||
export const isDbInitialized = (): boolean => {
|
||||
return databaseManager.isReady();
|
||||
};
|
||||
|
||||
export const getDbInstance = () => {
|
||||
return databaseManager.getDbSync();
|
||||
};
|
||||
|
||||
export const getDb = async (timeout?: number) => {
|
||||
return databaseManager.getDb(timeout);
|
||||
};
|
||||
Reference in New Issue
Block a user