Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-1537

Extend `Realm.open` convert a local Realm to a synced Realm

      Problem

      Once https://github.com/realm/realm-js/pull/4331 is merged our users need to add a lot of boilerplate code to use the feature:

      Unable to find source-code formatter for language: typescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      const app = new Realm.App("awesome-app");
      const user = await app.logIn(Realm.Credentials.anonymous());
      
      const localConfig = {
        path: "local.realm",
        schema: [Person, Dog],
      };
      
      // Copies a bundled realm to "local.realm"
      if (!Realm.exists(localConfig)) {
        Realm.copyBundledRealmFiles();
      }
      
      const localRealm = new Realm(localConfig);
      
      const remoteConfig = {
        schema: [Person, Dog],
        sync: {
          user,
          partitionValue,
        },
      };
      
      if (Realm.exists(remoteConfig)) {
        return Realm.open(remoteConfig);
      } else {
        localRealm.writeCopyTo(remoteConfig);
        localRealm.close();
        // Open the new remote Realm
        const syncedRealm = await Realm.open(remoteConfig);
        // Delete the old realm
        Realm.deleteFile(localConfig);
        return syncedRealm;
      }
      

      Solution

      Unable to find source-code formatter for language: typescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      // Copies a bundled realm to "local.realm"
      if (!Realm.exists({ path: "local.realm" })) {
        Realm.copyBundledRealmFiles();
      }
      
      // Automagically copies the local Realm into a synced Realm as it's opened.
      const syncedRealm = await Realm.open({
        path: "local.realm",
        sync: {
          user,
          partitionValue,
        },
      });
      

      How important is this improvement for you?

      Would be a major improvement

            Assignee:
            Unassigned Unassigned
            Reporter:
            kraen.hansen@mongodb.com Kræn Hansen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: