Add database options to ParseServer constructor and pass to MongoStorageAdapter
This commit is contained in:
@@ -10,12 +10,14 @@ const MongoSchemaCollectionName = '_SCHEMA';
|
||||
export class MongoStorageAdapter {
|
||||
// Private
|
||||
_uri: string;
|
||||
_options: Object;
|
||||
// Public
|
||||
connectionPromise;
|
||||
database;
|
||||
|
||||
constructor(uri: string) {
|
||||
constructor(uri: string, options: Object) {
|
||||
this._uri = uri;
|
||||
this._options = options;
|
||||
}
|
||||
|
||||
connect() {
|
||||
@@ -23,7 +25,7 @@ export class MongoStorageAdapter {
|
||||
return this.connectionPromise;
|
||||
}
|
||||
|
||||
this.connectionPromise = MongoClient.connect(this._uri).then(database => {
|
||||
this.connectionPromise = MongoClient.connect(this._uri, this._options).then(database => {
|
||||
this.database = database;
|
||||
});
|
||||
return this.connectionPromise;
|
||||
|
||||
@@ -24,6 +24,7 @@ let adapter = MongoStorageAdapter;
|
||||
let dbConnections = {};
|
||||
let databaseURI = DefaultDatabaseURI;
|
||||
let appDatabaseURIs = {};
|
||||
let appDatabaseOptions = {};
|
||||
|
||||
function setAdapter(databaseAdapter) {
|
||||
adapter = databaseAdapter;
|
||||
@@ -37,6 +38,10 @@ function setAppDatabaseURI(appId, uri) {
|
||||
appDatabaseURIs[appId] = uri;
|
||||
}
|
||||
|
||||
function setAppDatabaseOptions(appId: string, options: Object) {
|
||||
appDatabaseOptions[appId] = options;
|
||||
}
|
||||
|
||||
//Used by tests
|
||||
function clearDatabaseURIs() {
|
||||
appDatabaseURIs = {};
|
||||
@@ -50,7 +55,7 @@ function getDatabaseConnection(appId: string, collectionPrefix: string) {
|
||||
|
||||
var dbURI = (appDatabaseURIs[appId] ? appDatabaseURIs[appId] : databaseURI);
|
||||
|
||||
let storageAdapter = new adapter(dbURI);
|
||||
let storageAdapter = new adapter(dbURI, appDatabaseOptions[appId]);
|
||||
dbConnections[appId] = new DatabaseController(storageAdapter, {
|
||||
collectionPrefix: collectionPrefix
|
||||
});
|
||||
@@ -62,6 +67,7 @@ module.exports = {
|
||||
getDatabaseConnection: getDatabaseConnection,
|
||||
setAdapter: setAdapter,
|
||||
setDatabaseURI: setDatabaseURI,
|
||||
setAppDatabaseOptions: setAppDatabaseOptions,
|
||||
setAppDatabaseURI: setAppDatabaseURI,
|
||||
clearDatabaseURIs: clearDatabaseURIs,
|
||||
defaultDatabaseURI: databaseURI
|
||||
|
||||
@@ -84,6 +84,7 @@ function ParseServer({
|
||||
push,
|
||||
loggerAdapter,
|
||||
databaseURI = DatabaseAdapter.defaultDatabaseURI,
|
||||
databaseOptions,
|
||||
cloud,
|
||||
collectionPrefix = '',
|
||||
clientKey,
|
||||
@@ -120,6 +121,10 @@ function ParseServer({
|
||||
DatabaseAdapter.setAppDatabaseURI(appId, databaseURI);
|
||||
}
|
||||
|
||||
if (databaseOptions) {
|
||||
DatabaseAdapter.setAppDatabaseOptions(appId, databaseOptions);
|
||||
}
|
||||
|
||||
if (cloud) {
|
||||
addParseCloud();
|
||||
if (typeof cloud === 'function') {
|
||||
|
||||
Reference in New Issue
Block a user