diff --git a/src/appStart/StartHelper.tsx b/src/appStart/StartHelper.tsx index 4ef29e4..b7adf71 100644 --- a/src/appStart/StartHelper.tsx +++ b/src/appStart/StartHelper.tsx @@ -37,7 +37,9 @@ function onAppStart() { setTimeout(async () => { console.log('get'); - console.log(await BigDataManager.getEntry('users', 'test')); + const obj = (await BigDataManager.getEntry('users', 'test')); + console.log("obj",obj); + console.log("objAccName",obj.AccountName); console.log( 'user', await UserManager.getUser(MyUserManager.getSelectedUserId()), diff --git a/src/caj/helper/storage/bdm/get.ts b/src/caj/helper/storage/bdm/get.ts index 4fbb0f5..8c2ccd2 100644 --- a/src/caj/helper/storage/bdm/get.ts +++ b/src/caj/helper/storage/bdm/get.ts @@ -9,5 +9,7 @@ export const getEntry = async (dbName: databaseNames, key: possibleDBKeys) => { const schema = DBSchemas[dbName].details.properties; const val = realm.objectForPrimaryKey('users', key); + console.log('val', val); + return val; }; diff --git a/src/caj/helper/storage/bdm/getDB.ts b/src/caj/helper/storage/bdm/getDB.ts index 9b91895..ae8cc9f 100644 --- a/src/caj/helper/storage/bdm/getDB.ts +++ b/src/caj/helper/storage/bdm/getDB.ts @@ -12,7 +12,7 @@ type DBType = Realm; export interface DBObject { name: databaseNames; - schema: databaseConf; + schema: databaseConf<{[key: string]: string}>; db: DBType | undefined; lastUsedTimestamp?: timestamp; // when timeout is undefined then db is closed } @@ -52,7 +52,9 @@ export function closeAllDatabases() { } } -export async function openMyDatabase(schema: databaseConf): Promise { +export async function openMyDatabase( + schema: databaseConf<{[key: string]: string}>, +): Promise { const folderPath = MyUserManager.getSelectedUserId(); const path = folderPath + '/' + schema.filePath; diff --git a/src/caj/helper/storage/bdm/getDB.web.ts b/src/caj/helper/storage/bdm/getDB.web.ts index 2621f1f..245ce56 100644 --- a/src/caj/helper/storage/bdm/getDB.web.ts +++ b/src/caj/helper/storage/bdm/getDB.web.ts @@ -9,7 +9,7 @@ type DBType = IDBPDatabase; export interface DBObject { name: databaseNames; - schema: databaseConf; + schema: databaseConf<{[key: string]: string}>; db: DBType | undefined; lastUsedTimestamp?: timestamp; // when timeout is undefined then db is closed } @@ -50,7 +50,7 @@ export function closeAllDatabases() { } export async function openMyDatabase( - schema: databaseConf, + schema: databaseConf<{[key: string]: string}>, init?: boolean, ): Promise { const db = await openDB( diff --git a/src/caj/helper/storage/bdm/schemas.ts b/src/caj/helper/storage/bdm/schemas.ts index f51a774..c642114 100644 --- a/src/caj/helper/storage/bdm/schemas.ts +++ b/src/caj/helper/storage/bdm/schemas.ts @@ -2,7 +2,13 @@ import {usersDBMigration} from './migration'; import {chatDBMigration} from './migration'; import {databaseConf} from './types'; -const users: databaseConf = { +const usersProps = { + UserId: 'string', + AccountName: 'string', + Username: 'string', +}; + +const users: databaseConf = { filePath: 'users', version: 1, migration: () => { @@ -10,16 +16,17 @@ const users: databaseConf = { }, details: { name: 'users', - properties: { - UserId: 'string', - AccountName: 'string', - Username: 'string', - }, + properties: usersProps, primaryKey: 'UserId', }, }; -const chat: databaseConf = { +const chatProps = { + UserId: 'string', + msg: 'string', +}; + +const chat: databaseConf = { filePath: 'chat', version: 1, migration: () => { @@ -27,10 +34,7 @@ const chat: databaseConf = { }, details: { name: 'chat', - properties: { - UserId: 'string', - msg: 'string', - }, + properties: chatProps, primaryKey: 'UserId', }, }; diff --git a/src/caj/helper/storage/bdm/types.ts b/src/caj/helper/storage/bdm/types.ts index 1bfeff8..a0def77 100644 --- a/src/caj/helper/storage/bdm/types.ts +++ b/src/caj/helper/storage/bdm/types.ts @@ -1,13 +1,13 @@ export type databaseNames = 'users' | 'chat'; export type possibleDBKeys = string; -export interface databaseConf { +export interface databaseConf { filePath: string; version: number; migration?: any; details: { name: databaseNames; - properties: any; + properties: props; primaryKey: string; }; }