Skip to content

Commit aa0b405

Browse files
committed
Move Mongo database property directly to mongo adapter.
1 parent d8b308e commit aa0b405

File tree

5 files changed

+16
-23
lines changed

5 files changed

+16
-23
lines changed

spec/Schema.spec.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -520,11 +520,11 @@ describe('Schema', () => {
520520
return obj2.save();
521521
})
522522
.then(() => {
523-
config.database.db.collection('test__Join:aRelation:HasPointersAndRelations', { strict: true }, (err, coll) => {
523+
config.database.adapter.database.collection('test__Join:aRelation:HasPointersAndRelations', { strict: true }, (err, coll) => {
524524
expect(err).toEqual(null);
525525
config.database.loadSchema()
526-
.then(schema => schema.deleteField('aRelation', 'HasPointersAndRelations', config.database.db, 'test_'))
527-
.then(() => config.database.db.collection('test__Join:aRelation:HasPointersAndRelations', { strict: true }, (err, coll) => {
526+
.then(schema => schema.deleteField('aRelation', 'HasPointersAndRelations', config.database.adapter.database, 'test_'))
527+
.then(() => config.database.adapter.database.collection('test__Join:aRelation:HasPointersAndRelations', { strict: true }, (err, coll) => {
528528
expect(err).not.toEqual(null);
529529
done();
530530
}))
@@ -538,7 +538,7 @@ describe('Schema', () => {
538538
var obj2 = hasAllPODobject();
539539
var p = Parse.Object.saveAll([obj1, obj2])
540540
.then(() => config.database.loadSchema())
541-
.then(schema => schema.deleteField('aString', 'HasAllPOD', config.database.db, 'test_'))
541+
.then(schema => schema.deleteField('aString', 'HasAllPOD', config.database.adapter.database, 'test_'))
542542
.then(() => new Parse.Query('HasAllPOD').get(obj1.id))
543543
.then(obj1Reloaded => {
544544
expect(obj1Reloaded.get('aString')).toEqual(undefined);
@@ -568,7 +568,7 @@ describe('Schema', () => {
568568
expect(obj1.get('aPointer').id).toEqual(obj1.id);
569569
})
570570
.then(() => config.database.loadSchema())
571-
.then(schema => schema.deleteField('aPointer', 'NewClass', config.database.db, 'test_'))
571+
.then(schema => schema.deleteField('aPointer', 'NewClass', config.database.adapter.database, 'test_'))
572572
.then(() => new Parse.Query('NewClass').get(obj1.id))
573573
.then(obj1 => {
574574
expect(obj1.get('aPointer')).toEqual(undefined);

spec/schemas.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -710,10 +710,10 @@ describe('schemas', () => {
710710
}, (error, response, body) => {
711711
expect(response.statusCode).toEqual(200);
712712
expect(response.body).toEqual({});
713-
config.database.db.collection('test__Join:aRelation:MyOtherClass', { strict: true }, (err, coll) => {
713+
config.database.adapter.database.collection('test__Join:aRelation:MyOtherClass', { strict: true }, (err, coll) => {
714714
//Expect Join table to be gone
715715
expect(err).not.toEqual(null);
716-
config.database.db.collection('test_MyOtherClass', { strict: true }, (err, coll) => {
716+
config.database.adapter.database.collection('test_MyOtherClass', { strict: true }, (err, coll) => {
717717
// Expect data table to be gone
718718
expect(err).not.toEqual(null);
719719
request.get({

src/Adapters/Files/GridStoreAdapter.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class GridStoreAdapter extends FilesAdapter {
1111
// Returns a promise
1212
createFile(config, filename, data) {
1313
return config.database.connect().then(() => {
14-
let gridStore = new GridStore(config.database.db, filename, 'w');
14+
let gridStore = new GridStore(config.database.adapter.database, filename, 'w');
1515
return gridStore.open();
1616
}).then((gridStore) => {
1717
return gridStore.write(data);
@@ -22,7 +22,7 @@ export class GridStoreAdapter extends FilesAdapter {
2222

2323
deleteFile(config, filename) {
2424
return config.database.connect().then(() => {
25-
let gridStore = new GridStore(config.database.db, filename, 'w');
25+
let gridStore = new GridStore(config.database.adapter.database, filename, 'w');
2626
return gridStore.open();
2727
}).then((gridStore) => {
2828
return gridStore.unlink();
@@ -33,9 +33,9 @@ export class GridStoreAdapter extends FilesAdapter {
3333

3434
getFileData(config, filename) {
3535
return config.database.connect().then(() => {
36-
return GridStore.exist(config.database.db, filename);
36+
return GridStore.exist(config.database.adapter.database, filename);
3737
}).then(() => {
38-
let gridStore = new GridStore(config.database.db, filename, 'r');
38+
let gridStore = new GridStore(config.database.adapter.database, filename, 'r');
3939
return gridStore.open();
4040
}).then((gridStore) => {
4141
return gridStore.read();

src/Controllers/DatabaseController.js

+3-10
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,8 @@ function DatabaseController(adapter, { collectionPrefix } = {}) {
2424

2525
// Connects to the database. Returns a promise that resolves when the
2626
// connection is successful.
27-
// this.db will be populated with a Mongo "Db" object when the
28-
// promise resolves successfully.
2927
DatabaseController.prototype.connect = function() {
30-
if (this.adapter.connectionPromise) {
31-
return this.adapter.connectionPromise;
32-
}
33-
return this.adapter.connect().then(() => {
34-
this.db = this.adapter.database;
35-
});
28+
return this.adapter.connect();
3629
};
3730

3831
// Returns a promise for a Mongo collection.
@@ -47,7 +40,7 @@ DatabaseController.prototype.collection = function(className) {
4740

4841
DatabaseController.prototype.rawCollection = function(className) {
4942
return this.connect().then(() => {
50-
return this.db.collection(this.collectionPrefix + className);
43+
return this.adapter.database.collection(this.collectionPrefix + className);
5144
});
5245
};
5346

@@ -353,7 +346,7 @@ DatabaseController.prototype.deleteEverything = function() {
353346
this.schemaPromise = null;
354347

355348
return this.connect().then(() => {
356-
return this.db.collections();
349+
return this.adapter.database.collections();
357350
}).then((colls) => {
358351
var promises = [];
359352
for (var coll of colls) {

src/Routers/SchemasRouter.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ function modifySchema(req) {
164164
.then(() => schema.deleteField(
165165
submittedFieldName,
166166
className,
167-
req.config.database.db,
167+
req.config.database.adapter.database,
168168
req.config.database.collectionPrefix
169169
));
170170
deletionPromises.push(promise);
@@ -246,7 +246,7 @@ function deleteSchema(req) {
246246
//tried to delete non-existant class
247247
resolve({ response: {}});
248248
} else {
249-
removeJoinTables(req.config.database.db, req.config.database.collectionPrefix, doc.value)
249+
removeJoinTables(req.config.database.adapter.database, req.config.database.collectionPrefix, doc.value)
250250
.then(resolve, reject);
251251
}
252252
});

0 commit comments

Comments
 (0)