How to use the realm function in realm

To help you get started, we’ve selected a few realm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github liu-kaixin / mobile-realm / src / servers / realm / configure.js View on Github external
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();
}
github liu-kaixin / mobile-realm / src / servers / realm / configure.js View on Github external
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();
}
github realm / my-first-realm-app / react-native / QueryBasedSync / ToDo / src / components / LoginForm.js View on Github external
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 });
  }
github City-of-Helsinki / open-city-app / src / util / models.js View on Github external
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]);
  },
}
github andgly95 / Tailored-Nutrition / TailoredNutrition / ProfileService.js View on Github external
'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);
        })
github realm / my-first-realm-app / react-native / Permissions / ToDo / src / components / LoginForm.js View on Github external
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 });
  }
github mongrov / roverz / src / models / index.js View on Github external
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);
  }
github RocketChat / Rocket.Chat.ReactNative / app / lib / realm.js View on Github external
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;
					}
				}
			}
github NordicMuseum / Nordic-Museum-Audio-Guide / app / realm.js View on Github external
export const getRealmInstance = () => {
  if (realmInstance == null) {
    realmInstance = new Realm({
      schema: [TourStop, AudioContent, Durations],
      schemaVersion: SCHEMAVERSION,
      migration(oldRealm, newRealm) {
        newRealm.deleteAll();
      },
    });
  }

  return realmInstance;
};
github liu-kaixin / mobile-realm / src / servers / realm / index.js View on Github external
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