Skip to content

Instantly share code, notes, and snippets.

@nirinchev
Created September 25, 2019 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nirinchev/a1425d4e9739ad1028f8f18300720a8c to your computer and use it in GitHub Desktop.
Save nirinchev/a1425d4e9739ad1028f8f18300720a8c to your computer and use it in GitHub Desktop.
const Realm = require('realm');
//Schemas
const Weapons = {
name: 'Weapons',
properties: {
weaponName: 'string',
owner: 'string'
}
};
const Superheroes = {
name: 'Superheroes',
properties: {
name: 'string',
superPower: 'string',
weapon: 'string'
}
};
//setting the credentials
var cred = Realm.Sync.Credentials.usernamePassword("admin", "123");
console.log("credentials set...");
async function main() {
const currentUser = await Realm.Sync.User.login("https://testinstancerealm.us1.cloud.realm.io", cred)
console.log("logging user...");
let config = currentUser.createConfiguration();
config.schema = [Weapons];
config.sync.user = currentUser;
config.sync.url = "realms://testinstancerealm.us1.cloud.realm.io/node-js-test_1";
config.sync.fullSynchronization = true;
config.sync.validate_ssl = false;
console.log("Schema: " + config.schema.name + "\n" +
"User: " + config.sync.user.name + "\n" +
"Url: " + config.sync.url + "\n" +
"FullSync: " + config.sync.fullSynchronization + "\n" +
"Validate SSL: " + config.sync.validate_ssl + "\n" + "config done...\n");
const realm = await Realm.open(config);
console.log("realm opened with configs...")
let weapons = realm.objects('Weapons');
realm.write(() => {
var weapon = realm.create('Weapons',{
owner: 'Cap',
weaponName: 'Shield'
}, true)
})
await realm.syncSession.uploadAllLocalChanges();
console.log("data uploaded")
process.exit(0);
}
main().catch((err) => {
console.error(err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment