Skip to content

Instantly share code, notes, and snippets.

@ianpward
Last active September 20, 2017 20:28
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 ianpward/b725bdd9d77f75108f2520f436e5e1f6 to your computer and use it in GitHub Desktop.
Save ianpward/b725bdd9d77f75108f2520f436e5e1f6 to your computer and use it in GitHub Desktop.
Realm Data Adapter Node Script
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