database
parent
17399c518c
commit
014246a78b
|
@ -26,8 +26,9 @@ import {initDatabase} from '@caj/helper/storage/bdm/init';
|
||||||
|
|
||||||
const AnimationView = animated(View);
|
const AnimationView = animated(View);
|
||||||
|
|
||||||
function onAppStart() {
|
export async function onAppStart() {
|
||||||
initAppData().then(async () => {
|
await initAppData();
|
||||||
|
|
||||||
await initKey();
|
await initKey();
|
||||||
|
|
||||||
BigDataManager.initDatabase()
|
BigDataManager.initDatabase()
|
||||||
|
@ -59,7 +60,7 @@ function onAppStart() {
|
||||||
await BigDataManager.databases.chat.setEntry(
|
await BigDataManager.databases.chat.setEntry(
|
||||||
{
|
{
|
||||||
[chatDBKeys.UserId]: MyUserManager.getSelectedUserId(),
|
[chatDBKeys.UserId]: MyUserManager.getSelectedUserId(),
|
||||||
[chatDBKeys.msg]: 'heyho',
|
[chatDBKeys.data]: 'heyho',
|
||||||
},
|
},
|
||||||
chat.roomId,
|
chat.roomId,
|
||||||
);
|
);
|
||||||
|
@ -73,8 +74,7 @@ function onAppStart() {
|
||||||
[usrDBKeys.UserId]: 'test',
|
[usrDBKeys.UserId]: 'test',
|
||||||
[usrDBKeys.AccountName]: '#845613',
|
[usrDBKeys.AccountName]: '#845613',
|
||||||
[usrDBKeys.Username]: 'TestGroupVirtual',
|
[usrDBKeys.Username]: 'TestGroupVirtual',
|
||||||
[usrDBKeys.Description]:
|
[usrDBKeys.Description]: 'This is a test account that is not real. ^^',
|
||||||
'This is a test account that is not real. ^^',
|
|
||||||
[usrDBKeys.FollowersCount]: 2,
|
[usrDBKeys.FollowersCount]: 2,
|
||||||
[usrDBKeys.FollowingCount]: 24,
|
[usrDBKeys.FollowingCount]: 24,
|
||||||
[usrDBKeys.lastUpdateTimestamp]: 412341234,
|
[usrDBKeys.lastUpdateTimestamp]: 412341234,
|
||||||
|
@ -85,16 +85,13 @@ function onAppStart() {
|
||||||
[usrDBKeys.XpPoints]: 0,
|
[usrDBKeys.XpPoints]: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
store.dispatch(
|
store.dispatch(appNonSaveVarActions.setAppStatus(appStatus.APP_RUNNING));
|
||||||
appNonSaveVarActions.setAppStatus(appStatus.APP_RUNNING),
|
|
||||||
);
|
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error("Database Error! Can't start App :(", err);
|
console.error("Database Error! Can't start App :(", err);
|
||||||
});
|
});
|
||||||
|
|
||||||
//store.dispatch(actions.loadPreferences(appVar));
|
//store.dispatch(actions.loadPreferences(appVar));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function StartHelper() {
|
function StartHelper() {
|
||||||
|
@ -136,7 +133,11 @@ function StartHelper() {
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(onAppStart, []);
|
useEffect(() => {
|
||||||
|
(async () => {
|
||||||
|
await onAppStart();
|
||||||
|
})();
|
||||||
|
}, []);
|
||||||
|
|
||||||
if (currentAppStatus === appStatus.APP_RUNNING) return null;
|
if (currentAppStatus === appStatus.APP_RUNNING) return null;
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,7 @@ import MostPopularPasswords from '@caj/helper/password-quality-calculator/MostPo
|
||||||
import MyUserManager from '@caj/user/MyUserManager';
|
import MyUserManager from '@caj/user/MyUserManager';
|
||||||
|
|
||||||
import {Buffer} from 'buffer';
|
import {Buffer} from 'buffer';
|
||||||
|
import {onAppStart} from '@caj/../appStart/StartHelper';
|
||||||
|
|
||||||
// Load the popular passwords list
|
// Load the popular passwords list
|
||||||
PasswordQualityCalculator.PopularPasswords.load(MostPopularPasswords);
|
PasswordQualityCalculator.PopularPasswords.load(MostPopularPasswords);
|
||||||
|
@ -1129,7 +1130,7 @@ function StepFinal() {
|
||||||
WebSocketSessionId: '',
|
WebSocketSessionId: '',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(resp => {
|
.then(async resp => {
|
||||||
if (
|
if (
|
||||||
resp.response.XAuthorization !== '' &&
|
resp.response.XAuthorization !== '' &&
|
||||||
resp.response.UserId !== '' &&
|
resp.response.UserId !== '' &&
|
||||||
|
@ -1151,6 +1152,7 @@ function StepFinal() {
|
||||||
resp.response.XAuthorization,
|
resp.response.XAuthorization,
|
||||||
resp.response.WebSocketSessionId,
|
resp.response.WebSocketSessionId,
|
||||||
);
|
);
|
||||||
|
await onAppStart();
|
||||||
navigation.popToTop();
|
navigation.popToTop();
|
||||||
navigation.goBack();
|
navigation.goBack();
|
||||||
}
|
}
|
||||||
|
@ -1284,7 +1286,7 @@ function Login() {
|
||||||
resp.response.XAuthorization,
|
resp.response.XAuthorization,
|
||||||
resp.response.WebSocketSessionId,
|
resp.response.WebSocketSessionId,
|
||||||
)
|
)
|
||||||
.then(() => {
|
.then(async () => {
|
||||||
showToast(toast, {
|
showToast(toast, {
|
||||||
title: lang.account.login.success,
|
title: lang.account.login.success,
|
||||||
variant: 'solid',
|
variant: 'solid',
|
||||||
|
@ -1295,6 +1297,7 @@ function Login() {
|
||||||
});
|
});
|
||||||
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
await onAppStart();
|
||||||
navigation.goBack();
|
navigation.goBack();
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
import {appNonSaveVarActions} from '@caj/configs/appNonSaveVarReducer';
|
import {appNonSaveVarActions} from '@caj/configs/appNonSaveVarReducer';
|
||||||
|
import {initDatabase} from '@caj/helper/storage/bdm/init';
|
||||||
|
import DBSchemas from '@caj/helper/storage/bdm/schemas';
|
||||||
import BigDataManager from '@caj/helper/storage/BigDataManager';
|
import BigDataManager from '@caj/helper/storage/BigDataManager';
|
||||||
import {store} from '@caj/redux/store';
|
import {store} from '@caj/redux/store';
|
||||||
import {chatEntity} from './types';
|
import {chatEntity} from './types';
|
||||||
|
|
||||||
async function initChatDatabase(chat: chatEntity) {
|
async function initChatDatabase(chat: chatEntity) {
|
||||||
const keys = BigDataManager.databases.chatRoomInfos.keys;
|
const keys = BigDataManager.databases.chatRoomInfos.keys;
|
||||||
|
|
||||||
|
await initDatabase(DBSchemas.chat, chat.roomId);
|
||||||
|
|
||||||
await BigDataManager.databases.chatRoomInfos.setEntry({
|
await BigDataManager.databases.chatRoomInfos.setEntry({
|
||||||
[keys.RoomId]: chat.roomId,
|
[keys.RoomId]: chat.roomId,
|
||||||
[keys.initSyncId]: chat.initSyncId,
|
[keys.initSyncId]: chat.initSyncId,
|
||||||
|
|
|
@ -16,7 +16,7 @@ export const getEntry = async <T2 extends databaseConf<T, any>, T>(
|
||||||
const realm = await getDatabase(nameObj);
|
const realm = await getDatabase(nameObj);
|
||||||
|
|
||||||
const val = realm.objectForPrimaryKey<typeof schema.details.properties>(
|
const val = realm.objectForPrimaryKey<typeof schema.details.properties>(
|
||||||
dbName,
|
nameObj.name,
|
||||||
key,
|
key,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ export const getAllEntries = async <T2 extends databaseConf<T, any>, T>(
|
||||||
|
|
||||||
const realm = await getDatabase(nameObj);
|
const realm = await getDatabase(nameObj);
|
||||||
|
|
||||||
const val = realm.objects<typeof schema.details.properties>(dbName);
|
const val = realm.objects<typeof schema.details.properties>(nameObj.name);
|
||||||
|
|
||||||
return [...val] as T[];
|
return [...val] as T[];
|
||||||
};
|
};
|
||||||
|
|
|
@ -77,12 +77,17 @@ export async function openMyDatabase(
|
||||||
await RNFS.mkdir(RNFS.DocumentDirectoryPath + '/' + folderPath);
|
await RNFS.mkdir(RNFS.DocumentDirectoryPath + '/' + folderPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await Realm.open({
|
console.log('schema.details', schema.details);
|
||||||
|
|
||||||
|
const realm = await Realm.open({
|
||||||
schema: [schema.details as any],
|
schema: [schema.details as any],
|
||||||
schemaVersion: schema.version,
|
schemaVersion: schema.version,
|
||||||
path,
|
path,
|
||||||
encryptionKey: getKey(),
|
encryptionKey: getKey(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log('path', path);
|
||||||
|
return realm;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getDatabase(
|
export async function getDatabase(
|
||||||
|
|
|
@ -27,6 +27,7 @@ export const initDatabase = async (
|
||||||
name: schema.details.name,
|
name: schema.details.name,
|
||||||
suffix: fileSuffix,
|
suffix: fileSuffix,
|
||||||
};
|
};
|
||||||
|
console.log('initDatabase', _nameObj);
|
||||||
const name = mergeDBName(_nameObj);
|
const name = mergeDBName(_nameObj);
|
||||||
|
|
||||||
let dbObj: DBObject = {
|
let dbObj: DBObject = {
|
||||||
|
|
|
@ -5,21 +5,46 @@ import {setEntry} from '../set';
|
||||||
import {databaseConf, possibleDBKeys} from '../types';
|
import {databaseConf, possibleDBKeys} from '../types';
|
||||||
|
|
||||||
enum keys {
|
enum keys {
|
||||||
UserId = 'a',
|
syncID = "a",
|
||||||
msg = 'b',
|
UserId = 'b',
|
||||||
|
data = 'c',
|
||||||
|
massageType = "d",
|
||||||
|
created_at = "e",
|
||||||
|
received_by_server = "f",
|
||||||
|
received_by_target_clients = "g",
|
||||||
|
reply = "h",
|
||||||
|
reactions = "i",
|
||||||
|
hasRead = "j",
|
||||||
}
|
}
|
||||||
|
|
||||||
const name = 'chat';
|
const name = 'chat';
|
||||||
const primaryKey: keyof typeof propsDefault = keys.UserId;
|
const primaryKey: keyof typeof propsDefault = keys.UserId;
|
||||||
|
|
||||||
const propsType: {[key in keyof typeof propsDefault]: string} = {
|
const propsType: {[key in keyof typeof propsDefault]: string} = {
|
||||||
|
|
||||||
|
[keys.syncID]: "int",
|
||||||
[keys.UserId]: 'string',
|
[keys.UserId]: 'string',
|
||||||
[keys.msg]: 'string',
|
[keys.data]: 'data',
|
||||||
|
[keys.massageType]: "int",
|
||||||
|
[keys.created_at]: "int",
|
||||||
|
[keys.received_by_server]: "int",
|
||||||
|
[keys.received_by_target_clients]: "int",
|
||||||
|
[keys.reply]: "int",
|
||||||
|
[keys.reactions]: "i",
|
||||||
|
[keys.hasRead]: "j",
|
||||||
};
|
};
|
||||||
|
|
||||||
const propsDefault = {
|
const propsDefault = {
|
||||||
[keys.UserId]: 'test',
|
[keys.syncID]: "a",
|
||||||
[keys.msg]: 'test',
|
[keys.UserId]: 'b',
|
||||||
|
[keys.data]: 'c',
|
||||||
|
[keys.massageType]: "d",
|
||||||
|
[keys.created_at]: "e",
|
||||||
|
[keys.received_by_server]: "f",
|
||||||
|
[keys.received_by_target_clients]: "g",
|
||||||
|
[keys.reply]: "h",
|
||||||
|
[keys.reactions]: "i",
|
||||||
|
[keys.hasRead]: "j",
|
||||||
};
|
};
|
||||||
|
|
||||||
const thisSchema: databaseConf<typeof propsDefault, typeof keys> = {
|
const thisSchema: databaseConf<typeof propsDefault, typeof keys> = {
|
||||||
|
|
|
@ -12,6 +12,6 @@ export const setEntry = async <T2 extends databaseConf<T, any>, T>(
|
||||||
const realm = await getDatabase(nameObj);
|
const realm = await getDatabase(nameObj);
|
||||||
|
|
||||||
realm.write(() => {
|
realm.write(() => {
|
||||||
realm.create(dbName, value as any, Realm.UpdateMode.Modified);
|
realm.create(nameObj.name, value as any, Realm.UpdateMode.Modified);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue