Move Mongo database property directly to mongo adapter.

This commit is contained in:
Nikita Lutsenko
2016-02-27 02:37:38 -08:00
parent 997da898eb
commit 7215300c1e
5 changed files with 16 additions and 23 deletions

View File

@@ -520,11 +520,11 @@ describe('Schema', () => {
return obj2.save(); return obj2.save();
}) })
.then(() => { .then(() => {
config.database.db.collection('test__Join:aRelation:HasPointersAndRelations', { strict: true }, (err, coll) => { config.database.adapter.database.collection('test__Join:aRelation:HasPointersAndRelations', { strict: true }, (err, coll) => {
expect(err).toEqual(null); expect(err).toEqual(null);
config.database.loadSchema() config.database.loadSchema()
.then(schema => schema.deleteField('aRelation', 'HasPointersAndRelations', config.database.db, 'test_')) .then(schema => schema.deleteField('aRelation', 'HasPointersAndRelations', config.database.adapter.database, 'test_'))
.then(() => config.database.db.collection('test__Join:aRelation:HasPointersAndRelations', { strict: true }, (err, coll) => { .then(() => config.database.adapter.database.collection('test__Join:aRelation:HasPointersAndRelations', { strict: true }, (err, coll) => {
expect(err).not.toEqual(null); expect(err).not.toEqual(null);
done(); done();
})) }))
@@ -538,7 +538,7 @@ describe('Schema', () => {
var obj2 = hasAllPODobject(); var obj2 = hasAllPODobject();
var p = Parse.Object.saveAll([obj1, obj2]) var p = Parse.Object.saveAll([obj1, obj2])
.then(() => config.database.loadSchema()) .then(() => config.database.loadSchema())
.then(schema => schema.deleteField('aString', 'HasAllPOD', config.database.db, 'test_')) .then(schema => schema.deleteField('aString', 'HasAllPOD', config.database.adapter.database, 'test_'))
.then(() => new Parse.Query('HasAllPOD').get(obj1.id)) .then(() => new Parse.Query('HasAllPOD').get(obj1.id))
.then(obj1Reloaded => { .then(obj1Reloaded => {
expect(obj1Reloaded.get('aString')).toEqual(undefined); expect(obj1Reloaded.get('aString')).toEqual(undefined);
@@ -568,7 +568,7 @@ describe('Schema', () => {
expect(obj1.get('aPointer').id).toEqual(obj1.id); expect(obj1.get('aPointer').id).toEqual(obj1.id);
}) })
.then(() => config.database.loadSchema()) .then(() => config.database.loadSchema())
.then(schema => schema.deleteField('aPointer', 'NewClass', config.database.db, 'test_')) .then(schema => schema.deleteField('aPointer', 'NewClass', config.database.adapter.database, 'test_'))
.then(() => new Parse.Query('NewClass').get(obj1.id)) .then(() => new Parse.Query('NewClass').get(obj1.id))
.then(obj1 => { .then(obj1 => {
expect(obj1.get('aPointer')).toEqual(undefined); expect(obj1.get('aPointer')).toEqual(undefined);

View File

@@ -710,10 +710,10 @@ describe('schemas', () => {
}, (error, response, body) => { }, (error, response, body) => {
expect(response.statusCode).toEqual(200); expect(response.statusCode).toEqual(200);
expect(response.body).toEqual({}); expect(response.body).toEqual({});
config.database.db.collection('test__Join:aRelation:MyOtherClass', { strict: true }, (err, coll) => { config.database.adapter.database.collection('test__Join:aRelation:MyOtherClass', { strict: true }, (err, coll) => {
//Expect Join table to be gone //Expect Join table to be gone
expect(err).not.toEqual(null); expect(err).not.toEqual(null);
config.database.db.collection('test_MyOtherClass', { strict: true }, (err, coll) => { config.database.adapter.database.collection('test_MyOtherClass', { strict: true }, (err, coll) => {
// Expect data table to be gone // Expect data table to be gone
expect(err).not.toEqual(null); expect(err).not.toEqual(null);
request.get({ request.get({

View File

@@ -11,7 +11,7 @@ export class GridStoreAdapter extends FilesAdapter {
// Returns a promise // Returns a promise
createFile(config, filename, data) { createFile(config, filename, data) {
return config.database.connect().then(() => { 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(); return gridStore.open();
}).then((gridStore) => { }).then((gridStore) => {
return gridStore.write(data); return gridStore.write(data);
@@ -22,7 +22,7 @@ export class GridStoreAdapter extends FilesAdapter {
deleteFile(config, filename) { deleteFile(config, filename) {
return config.database.connect().then(() => { 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(); return gridStore.open();
}).then((gridStore) => { }).then((gridStore) => {
return gridStore.unlink(); return gridStore.unlink();
@@ -33,9 +33,9 @@ export class GridStoreAdapter extends FilesAdapter {
getFileData(config, filename) { getFileData(config, filename) {
return config.database.connect().then(() => { return config.database.connect().then(() => {
return GridStore.exist(config.database.db, filename); return GridStore.exist(config.database.adapter.database, filename);
}).then(() => { }).then(() => {
let gridStore = new GridStore(config.database.db, filename, 'r'); let gridStore = new GridStore(config.database.adapter.database, filename, 'r');
return gridStore.open(); return gridStore.open();
}).then((gridStore) => { }).then((gridStore) => {
return gridStore.read(); return gridStore.read();

View File

@@ -24,15 +24,8 @@ function DatabaseController(adapter, { collectionPrefix } = {}) {
// Connects to the database. Returns a promise that resolves when the // Connects to the database. Returns a promise that resolves when the
// connection is successful. // connection is successful.
// this.db will be populated with a Mongo "Db" object when the
// promise resolves successfully.
DatabaseController.prototype.connect = function() { DatabaseController.prototype.connect = function() {
if (this.adapter.connectionPromise) { return this.adapter.connect();
return this.adapter.connectionPromise;
}
return this.adapter.connect().then(() => {
this.db = this.adapter.database;
});
}; };
// Returns a promise for a Mongo collection. // Returns a promise for a Mongo collection.
@@ -47,7 +40,7 @@ DatabaseController.prototype.collection = function(className) {
DatabaseController.prototype.rawCollection = function(className) { DatabaseController.prototype.rawCollection = function(className) {
return this.connect().then(() => { 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; this.schemaPromise = null;
return this.connect().then(() => { return this.connect().then(() => {
return this.db.collections(); return this.adapter.database.collections();
}).then((colls) => { }).then((colls) => {
var promises = []; var promises = [];
for (var coll of colls) { for (var coll of colls) {

View File

@@ -164,7 +164,7 @@ function modifySchema(req) {
.then(() => schema.deleteField( .then(() => schema.deleteField(
submittedFieldName, submittedFieldName,
className, className,
req.config.database.db, req.config.database.adapter.database,
req.config.database.collectionPrefix req.config.database.collectionPrefix
)); ));
deletionPromises.push(promise); deletionPromises.push(promise);
@@ -246,7 +246,7 @@ function deleteSchema(req) {
//tried to delete non-existant class //tried to delete non-existant class
resolve({ response: {}}); resolve({ response: {}});
} else { } 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); .then(resolve, reject);
} }
}); });