How to use the realm.defaultPath 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 realm / realm-js / tests / spec / unit_tests.js View on Github external
Realm.copyBundledRealmFiles = function () {
    let sourceDir = path.join(__dirname, '../data');
    let destinationDir = path.dirname(Realm.defaultPath);

    for (let filename of fs.readdirSync(sourceDir)) {
        let src = path.join(sourceDir, filename);
        let dest = path.join(destinationDir, filename);

        // If the destination file already exists, then don't overwrite it.
        try {
            fs.accessSync(dest);
            continue;
        } catch (e) { }

        fs.writeFileSync(dest, fs.readFileSync(src));
    }
};
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 / realm-js / tests / js / realm-tests.js View on Github external
testRealmSchemaVersion: function() {
        TestCase.assertEqual(Realm.schemaVersion(Realm.defaultPath), -1);

        let realm = new Realm({schema: []});
        TestCase.assertEqual(realm.schemaVersion, 0);
        TestCase.assertEqual(Realm.schemaVersion(Realm.defaultPath), 0);

        realm = new Realm({schema: [], schemaVersion: 2, path: 'another.realm'});
        TestCase.assertEqual(realm.schemaVersion, 2);
        TestCase.assertEqual(Realm.schemaVersion('another.realm'), 2);
    },
github realm / realm-js / tests / js / realm-tests.js View on Github external
testDefaultPath: function() {
        const defaultPath = Realm.defaultPath;
        let defaultRealm = new Realm({schema: []});
        TestCase.assertEqual(defaultRealm.path, Realm.defaultPath);

        try {
            const newPath = `${Realm.defaultPath.substring(0, defaultPath.lastIndexOf(pathSeparator) + 1)}default2.realm`;
            Realm.defaultPath = newPath;
            defaultRealm = new Realm({schema: []});
            TestCase.assertEqual(defaultRealm.path, newPath, "should use updated default realm path");
            TestCase.assertEqual(Realm.defaultPath, newPath, "defaultPath should have been updated");
        } finally {
            Realm.defaultPath = defaultPath;
        }
    },
github realm / realm-js / tests / js / util.js View on Github external
exports.realmPathForFile = function(str) {
    var path = Realm.defaultPath;
    return path.substring(0, path.lastIndexOf("/") + 1) + str;
};
github bankifyio / redux-persist-realm / index.js View on Github external
function createRealmAccess(path = Realm.defaultPath) {
  let __realm = null;
  return async function accessRealm() {
    if (!__realm) {
      try {
        __realm = await Realm.open({
          schema: [ITEM_SCHEMA],
          path
        });
      } catch (error) {
        throw error;
      }
    }
    return __realm;
  };
}
github stage88 / react-weather / js / realm / configure.js View on Github external
function configureRealm() {
  var schema = new Schema();

  var next = Realm.schemaVersion(Realm.defaultPath);
  if (next > 0) {
    while (next < schema.schemas.length) {
      var migratedSchema = schema.schemas[next++];
      var migratedRealm = new Realm(migratedSchema);
      migratedRealm.close();
    }
  }

  var current = schema.current();
  var realm = new Realm(current);
  realm.close();
}