add realm

This commit is contained in:
Vincent BRIDIER 2022-09-29 16:22:58 +02:00
parent 9a77fef3dc
commit 7c2a76c4ed
No known key found for this signature in database
GPG key ID: 8571BFA20420D512
6 changed files with 2331 additions and 89 deletions

1690
ComApp/package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -17,7 +17,8 @@
"lodash": "^4.17.21",
"npm": "^8.19.2",
"react": "18.1.0",
"react-native": "0.70.1"
"react-native": "0.70.1",
"realm": "^11.0.0-rc.2"
},
"devDependencies": {
"@babel/core": "^7.12.9",

View file

@ -6,6 +6,8 @@ import axios from 'axios';
import NetInfo from "@react-native-community/netinfo";
// Translations
import i18n from "../../I18n";
// Database
import { Setting } from "../../Database";
const api_token = 'toto';
@ -28,7 +30,7 @@ class InstallController {
_.forEach(response.data.datas, function (value, key) {
switch (key) {
case "MainColor":
console.log("MainColor");
Setting.add({ key: key, value: value });
break;
case "SquaredLogo":
console.log("SquaredLogo");
@ -43,13 +45,14 @@ class InstallController {
console.log("HomeButtonImage");
break;
}
});
});
} else {
alert(i18n.t("error.error_has_occurred"));
}
}
})
.catch(function (error) {
console.log(error)
alert(i18n.t("error.error_has_occurred"));
})
} else {

View file

@ -0,0 +1,23 @@
class SettingModel {
constructor(realm) {
this.schema = 'Settings';
this.realm = realm;
}
add(data) {
this.realm.write(() => {
if (data.id === undefined) {
let id: any = this.realm.objects(this.schema).max('id');
data.id = id === undefined ? 1 : id + 1;
}
try {
this.realm.create(this.schema, data, 'never');
} catch (e) {
console.log('db setting add', e);
}
});
}
}
export default SettingModel;

27
ComApp/src/Database.js Normal file
View file

@ -0,0 +1,27 @@
import Realm from "realm";
// Models
import SettingModel from "./App/Models/Setting";
const SettingsSchema = {
name: 'Settings',
primaryKey: 'id',
properties: {
id: 'int',
key: 'string',
value: 'string',
},
};
const Database = {
schema: [
SettingsSchema,
],
//encryptionKey: new Int8Array(64)
};
let realm = new Realm(Database);
let Setting = new SettingModel(realm);
export {
Setting
}

File diff suppressed because it is too large Load diff