Move Mongo database property directly to mongo adapter.
This commit is contained in:
@@ -11,7 +11,7 @@ export class GridStoreAdapter extends FilesAdapter {
|
||||
// Returns a promise
|
||||
createFile(config, filename, data) {
|
||||
return config.database.connect().then(() => {
|
||||
let gridStore = new GridStore(config.database.db, filename, 'w');
|
||||
let gridStore = new GridStore(config.database.adapter.database, filename, 'w');
|
||||
return gridStore.open();
|
||||
}).then((gridStore) => {
|
||||
return gridStore.write(data);
|
||||
@@ -22,7 +22,7 @@ export class GridStoreAdapter extends FilesAdapter {
|
||||
|
||||
deleteFile(config, filename) {
|
||||
return config.database.connect().then(() => {
|
||||
let gridStore = new GridStore(config.database.db, filename, 'w');
|
||||
let gridStore = new GridStore(config.database.adapter.database, filename, 'w');
|
||||
return gridStore.open();
|
||||
}).then((gridStore) => {
|
||||
return gridStore.unlink();
|
||||
@@ -33,9 +33,9 @@ export class GridStoreAdapter extends FilesAdapter {
|
||||
|
||||
getFileData(config, filename) {
|
||||
return config.database.connect().then(() => {
|
||||
return GridStore.exist(config.database.db, filename);
|
||||
return GridStore.exist(config.database.adapter.database, filename);
|
||||
}).then(() => {
|
||||
let gridStore = new GridStore(config.database.db, filename, 'r');
|
||||
let gridStore = new GridStore(config.database.adapter.database, filename, 'r');
|
||||
return gridStore.open();
|
||||
}).then((gridStore) => {
|
||||
return gridStore.read();
|
||||
|
||||
@@ -24,15 +24,8 @@ function DatabaseController(adapter, { collectionPrefix } = {}) {
|
||||
|
||||
// Connects to the database. Returns a promise that resolves when the
|
||||
// connection is successful.
|
||||
// this.db will be populated with a Mongo "Db" object when the
|
||||
// promise resolves successfully.
|
||||
DatabaseController.prototype.connect = function() {
|
||||
if (this.adapter.connectionPromise) {
|
||||
return this.adapter.connectionPromise;
|
||||
}
|
||||
return this.adapter.connect().then(() => {
|
||||
this.db = this.adapter.database;
|
||||
});
|
||||
return this.adapter.connect();
|
||||
};
|
||||
|
||||
// Returns a promise for a Mongo collection.
|
||||
@@ -47,7 +40,7 @@ DatabaseController.prototype.collection = function(className) {
|
||||
|
||||
DatabaseController.prototype.rawCollection = function(className) {
|
||||
return this.connect().then(() => {
|
||||
return this.db.collection(this.collectionPrefix + className);
|
||||
return this.adapter.database.collection(this.collectionPrefix + className);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -353,7 +346,7 @@ DatabaseController.prototype.deleteEverything = function() {
|
||||
this.schemaPromise = null;
|
||||
|
||||
return this.connect().then(() => {
|
||||
return this.db.collections();
|
||||
return this.adapter.database.collections();
|
||||
}).then((colls) => {
|
||||
var promises = [];
|
||||
for (var coll of colls) {
|
||||
|
||||
@@ -164,7 +164,7 @@ function modifySchema(req) {
|
||||
.then(() => schema.deleteField(
|
||||
submittedFieldName,
|
||||
className,
|
||||
req.config.database.db,
|
||||
req.config.database.adapter.database,
|
||||
req.config.database.collectionPrefix
|
||||
));
|
||||
deletionPromises.push(promise);
|
||||
@@ -246,7 +246,7 @@ function deleteSchema(req) {
|
||||
//tried to delete non-existant class
|
||||
resolve({ response: {}});
|
||||
} else {
|
||||
removeJoinTables(req.config.database.db, req.config.database.collectionPrefix, doc.value)
|
||||
removeJoinTables(req.config.database.adapter.database, req.config.database.collectionPrefix, doc.value)
|
||||
.then(resolve, reject);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user