alpha
parent
b8f15fdf26
commit
a9b8cb574a
|
@ -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()),
|
||||
|
|
|
@ -9,5 +9,7 @@ export const getEntry = async (dbName: databaseNames, key: possibleDBKeys) => {
|
|||
const schema = DBSchemas[dbName].details.properties;
|
||||
|
||||
const val = realm.objectForPrimaryKey<typeof schema>('users', key);
|
||||
console.log('val', val);
|
||||
|
||||
return val;
|
||||
};
|
||||
|
|
|
@ -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<DBType> {
|
||||
export async function openMyDatabase(
|
||||
schema: databaseConf<{[key: string]: string}>,
|
||||
): Promise<DBType> {
|
||||
const folderPath = MyUserManager.getSelectedUserId();
|
||||
const path = folderPath + '/' + schema.filePath;
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ type DBType = IDBPDatabase<unknown>;
|
|||
|
||||
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<DBType> {
|
||||
const db = await openDB(
|
||||
|
|
|
@ -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<typeof usersProps> = {
|
||||
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<typeof chatProps> = {
|
||||
filePath: 'chat',
|
||||
version: 1,
|
||||
migration: () => {
|
||||
|
@ -27,10 +34,7 @@ const chat: databaseConf = {
|
|||
},
|
||||
details: {
|
||||
name: 'chat',
|
||||
properties: {
|
||||
UserId: 'string',
|
||||
msg: 'string',
|
||||
},
|
||||
properties: chatProps,
|
||||
primaryKey: 'UserId',
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
export type databaseNames = 'users' | 'chat';
|
||||
export type possibleDBKeys = string;
|
||||
|
||||
export interface databaseConf {
|
||||
export interface databaseConf<props> {
|
||||
filePath: string;
|
||||
version: number;
|
||||
migration?: any;
|
||||
details: {
|
||||
name: databaseNames;
|
||||
properties: any;
|
||||
properties: props;
|
||||
primaryKey: string;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue