-
-
Save nirinchev/a1425d4e9739ad1028f8f18300720a8c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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