Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
console.log('初始化 ================> ')
// && DeviceInfo.isEmulator()
if (__DEV__ && Platform.OS === 'ios') {
Realm.defaultPath = '/Users/Shared/data/data.realm'
}
console.log('Realm.defaultPath:', Realm.defaultPath);
var next = Realm.schemaVersion(Realm.defaultPath);
if (next > 0) {
while (next < schemas.length) {
const migratedSchema = schemas[next++];
const migratedRealm = new Realm(migratedSchema);
migratedRealm.close();
}
}
const getNewSchemas = schemas[schemas.length - 1];
const realm = new Realm(getNewSchemas);
// realm.close();
}
function configSchema() {
console.log('初始化 ================> ')
// && DeviceInfo.isEmulator()
if (__DEV__ && Platform.OS === 'ios') {
Realm.defaultPath = '/Users/Shared/data/data.realm'
}
console.log('Realm.defaultPath:', Realm.defaultPath);
var next = Realm.schemaVersion(Realm.defaultPath);
if (next > 0) {
while (next < schemas.length) {
const migratedSchema = schemas[next++];
const migratedRealm = new Realm(migratedSchema);
migratedRealm.close();
}
}
const getNewSchemas = schemas[schemas.length - 1];
const realm = new Realm(getNewSchemas);
// realm.close();
}
onAuthenticated(user) {
// Create a configuration to open the default Realm
const config = user.createConfiguration({
schema: [Project, Item]
});
// Open the Realm
const realm = new Realm(config);
// Navigate to the main scene
Actions.authenticated({ user, realm });
}
import Realm from 'realm';
const SERVICE_REQUEST_MODEL = 'ServiceRequest';
const SERVICE_REQUEST_ID_FIELD = 'serviceRequestId';
// Holds all Service request IDs submitted by the user.
const ServiceRequestSchema = {
name: SERVICE_REQUEST_MODEL,
properties: {
serviceRequestId: {type: 'string'},
}
};
const realm = new Realm({schema: [ServiceRequestSchema]});
module.exports = {
// Insert given serviceRequest to the database
insert: function(serviceRequestId) {
realm.write(()=> {
savedServiceRequest = realm.create(SERVICE_REQUEST_MODEL, {serviceRequestId: serviceRequestId});
});
},
// Return all data stored in the ServiceRequest model. Returns serviceRequests in an array
fetchAllServiceRequests: function() {
var serviceRequests = realm.objects(SERVICE_REQUEST_MODEL);
return serviceRequests.length === 0 ? [] : Object.keys(serviceRequests).map(key => Object.values(serviceRequests[key])[0]);
},
}
'use strict';
// https://hellokoding.com/todo-app-with-react-native-realm/
// The link above was followed
import Realm from 'realm';
import React, { Component } from 'react';
let repository = new Realm({
schema: [{
name: 'Profile',
primaryKey: 'Email',
properties: {
Email: 'string',
password: 'string',
username: 'string'
}
}]
});
let ProfileService = {
save: function(profile){
repository.write(() => {
repository.create('Profile', profile);
})
onAuthenticated(user) {
// Create a configuration to open the default Realm
const config = user.createConfiguration({
schema: [Project, Item]
});
// Open the Realm
const realm = new Realm(config);
// Navigate to the main scene
Actions.authenticated({ user, realm });
}
loadDb(path) {
AppUtil.debug(`realm set to: ${path}`, Constants.MODULE);
if (this.realm) {
// check if already loaded realm is same
if (path === Database._dbPath) return;
this.realm.close();
}
AppUtil.debug(`loading realm: ${path}`, Constants.MODULE);
const db = SchemaV1;
db.path = path;
Database._realm = new Realm(SchemaV1);
this.initManagers(this.realm);
this.setDBPath(path);
}
permissionsSchema,
url,
frequentlyUsedEmojiSchema,
customEmojisSchema,
messagesReactionsSchema,
rolesSchema,
uploadsSchema,
slashCommandSchema,
messagesTranslationsSchema
];
const inMemorySchema = [usersTypingSchema, activeUsersSchema];
class DB {
databases = {
serversDB: new Realm({
path: `${ RNRealmPath.realmPath }default.realm`,
schema: [
userSchema,
serversSchema
],
schemaVersion: 10,
migration: (oldRealm, newRealm) => {
if (oldRealm.schemaVersion >= 1 && newRealm.schemaVersion <= 9) {
const newServers = newRealm.objects('servers');
// eslint-disable-next-line no-plusplus
for (let i = 0; i < newServers.length; i++) {
newServers[i].roomsUpdatedAt = null;
}
}
}
export const getRealmInstance = () => {
if (realmInstance == null) {
realmInstance = new Realm({
schema: [TourStop, AudioContent, Durations],
schemaVersion: SCHEMAVERSION,
migration(oldRealm, newRealm) {
newRealm.deleteAll();
},
});
}
return realmInstance;
};
res[key] = cascadingCopy(toJS(object[key], toStr));
//非普通对象,非观测对象,需递归复制,无需toJS转化
} else if ((object[key] instanceof Map) || (object[key] instanceof Array) || (object[key] instanceof Object)) {
res[key] = cascadingCopy(object[key], toStr);
} else {
//普通对象,直接复制
res[key] = _dealObj(object[key], toStr);
}
}
return res;
}
return object;
}
const realm = new Realm(schemas[schemas.length - 1]);
realm.cascadingDelete = cascadingDelete;
realm.cascadingCopy = cascadingCopy;
export default realm