-
-
Save ianpward/b725bdd9d77f75108f2520f436e5e1f6 to your computer and use it in GitHub Desktop.
Realm Data Adapter Node Script
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'); | |
const fs = require('fs'); | |
const path = require('path'); | |
const PostgresAdapter = require('realm-data-adapters').PostgresAdapter; | |
const Config = require('./config'); | |
const Models = require('./realmmodels'); | |
// Unlock Data Connector APIs | |
Realm.Sync.setAccessToken(Config.feature_token); | |
const admin_user = Realm.Sync.User.adminUser(Config.admin_user_token); | |
// Print out uncaught exceptions | |
process.on('uncaughtException', (err) => console.log(err)); | |
var adapter = new PostgresAdapter({ | |
// Realm configuration parameters for connecting to ROS | |
realmConfig: { | |
server: Config.realm_object_server_url, // or specify your realm-object-server location | |
user: admin_user, | |
}, | |
dbName: Config.database_name, | |
// Postgres configuration and database name | |
postgresConfig: Config.postgres_config, | |
resetPostgresReplicationSlot: true, | |
// Set to true to create the Postgres DB if not already created | |
createPostgresDB: true, | |
initializeRealmFromPostgres: false, | |
// Map of custom types to Postgres types | |
/*customPostgresTypes: { | |
'USER-DEFINED': 'text', | |
'ARRAY': 'text', | |
'mpaa_rating': 'text', | |
'year': 'integer', | |
},*/ | |
// Set to true to indicate Postgres tables should be created and | |
// properties added to these tables based on schema additions | |
// made in Realm. If set to false any desired changes to the | |
// Postgres schema will need to be made external to the adapter. | |
applyRealmSchemaChangesToPostgres: true, | |
// Only match a single Realm called 'myRealm' | |
realmRegex: Config.target_realm_path, | |
// Specify the Realm name all Postgres changes should be applied to | |
mapPostgresChangeToRealmPath: Config.target_realm_path, | |
// Specify the Realm objects we want to replicate in Postgres. | |
// Any types or properties not specified here will not be replicated | |
schema: Models, | |
printCommandsToConsole: true, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment