Skip to content

Commit d78c274

Browse files
committed
Rename ExportAdapter to DatabaseController.
1 parent 10efd5d commit d78c274

File tree

7 files changed

+46
-48
lines changed

7 files changed

+46
-48
lines changed

spec/DatabaseController.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var DatabaseController = require('../src/Controllers/DatabaseController');
2+
3+
describe('DatabaseController', () => {
4+
it('can be constructed', (done) => {
5+
var database = new DatabaseController('mongodb://localhost:27017/test',
6+
{
7+
collectionPrefix: 'test_'
8+
});
9+
database.connect().then(done, (error) => {
10+
console.log('error', error.stack);
11+
fail();
12+
});
13+
});
14+
15+
});

spec/ExportAdapter.spec.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/Adapters/Files/FilesAdapter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// * getFileLocation(config, request, filename)
99
//
1010
// Default is GridStoreAdapter, which requires mongo
11-
// and for the API server to be using the ExportAdapter
11+
// and for the API server to be using the DatabaseController with Mongo
1212
// database adapter.
1313

1414
export class FilesAdapter {

src/ExportAdapter.js renamed to src/Controllers/DatabaseController.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ var mongodb = require('mongodb');
55
var MongoClient = mongodb.MongoClient;
66
var Parse = require('parse/node').Parse;
77

8-
var Schema = require('./Schema');
9-
var transform = require('./transform');
8+
var Schema = require('./../Schema');
9+
var transform = require('./../transform');
1010

1111
// options can contain:
1212
// collectionPrefix: the string to put in front of every collection name.
13-
function ExportAdapter(mongoURI, options = {}) {
13+
function DatabaseController(mongoURI, options = {}) {
1414
this.mongoURI = mongoURI;
1515

1616
this.collectionPrefix = options.collectionPrefix;
@@ -27,7 +27,7 @@ function ExportAdapter(mongoURI, options = {}) {
2727
// connection is successful.
2828
// this.db will be populated with a Mongo "Db" object when the
2929
// promise resolves successfully.
30-
ExportAdapter.prototype.connect = function() {
30+
DatabaseController.prototype.connect = function() {
3131
if (this.connectionPromise) {
3232
// There's already a connection in progress.
3333
return this.connectionPromise;
@@ -43,15 +43,15 @@ ExportAdapter.prototype.connect = function() {
4343

4444
// Returns a promise for a Mongo collection.
4545
// Generally just for internal use.
46-
ExportAdapter.prototype.collection = function(className) {
46+
DatabaseController.prototype.collection = function(className) {
4747
if (!Schema.classNameIsValid(className)) {
4848
throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME,
4949
'invalid className: ' + className);
5050
}
5151
return this.rawCollection(className);
5252
};
5353

54-
ExportAdapter.prototype.rawCollection = function(className) {
54+
DatabaseController.prototype.rawCollection = function(className) {
5555
return this.connect().then(() => {
5656
return this.db.collection(this.collectionPrefix + className);
5757
});
@@ -64,7 +64,7 @@ function returnsTrue() {
6464
// Returns a promise for a schema object.
6565
// If we are provided a acceptor, then we run it on the schema.
6666
// If the schema isn't accepted, we reload it at most once.
67-
ExportAdapter.prototype.loadSchema = function(acceptor = returnsTrue) {
67+
DatabaseController.prototype.loadSchema = function(acceptor = returnsTrue) {
6868

6969
if (!this.schemaPromise) {
7070
this.schemaPromise = this.collection('_SCHEMA').then((coll) => {
@@ -88,8 +88,8 @@ ExportAdapter.prototype.loadSchema = function(acceptor = returnsTrue) {
8888

8989
// Returns a promise for the classname that is related to the given
9090
// classname through the key.
91-
// TODO: make this not in the ExportAdapter interface
92-
ExportAdapter.prototype.redirectClassNameForKey = function(className, key) {
91+
// TODO: make this not in the DatabaseController interface
92+
DatabaseController.prototype.redirectClassNameForKey = function(className, key) {
9393
return this.loadSchema().then((schema) => {
9494
var t = schema.getExpectedType(className, key);
9595
var match = t.match(/^relation<(.*)>$/);
@@ -105,15 +105,15 @@ ExportAdapter.prototype.redirectClassNameForKey = function(className, key) {
105105
// Returns a promise that resolves to the new schema.
106106
// This does not update this.schema, because in a situation like a
107107
// batch request, that could confuse other users of the schema.
108-
ExportAdapter.prototype.validateObject = function(className, object, query) {
108+
DatabaseController.prototype.validateObject = function(className, object, query) {
109109
return this.loadSchema().then((schema) => {
110110
return schema.validateObject(className, object, query);
111111
});
112112
};
113113

114114
// Like transform.untransformObject but you need to provide a className.
115115
// Filters out any data that shouldn't be on this REST-formatted object.
116-
ExportAdapter.prototype.untransformObject = function(
116+
DatabaseController.prototype.untransformObject = function(
117117
schema, isMaster, aclGroup, className, mongoObject) {
118118
var object = transform.untransformObject(schema, className, mongoObject);
119119

@@ -138,7 +138,7 @@ ExportAdapter.prototype.untransformObject = function(
138138
// acl: a list of strings. If the object to be updated has an ACL,
139139
// one of the provided strings must provide the caller with
140140
// write permissions.
141-
ExportAdapter.prototype.update = function(className, query, update, options) {
141+
DatabaseController.prototype.update = function(className, query, update, options) {
142142
var acceptor = function(schema) {
143143
return schema.hasKeys(className, Object.keys(query));
144144
};
@@ -196,7 +196,7 @@ ExportAdapter.prototype.update = function(className, query, update, options) {
196196
// Returns a promise that resolves successfully when these are
197197
// processed.
198198
// This mutates update.
199-
ExportAdapter.prototype.handleRelationUpdates = function(className,
199+
DatabaseController.prototype.handleRelationUpdates = function(className,
200200
objectId,
201201
update) {
202202
var pending = [];
@@ -243,7 +243,7 @@ ExportAdapter.prototype.handleRelationUpdates = function(className,
243243

244244
// Adds a relation.
245245
// Returns a promise that resolves successfully iff the add was successful.
246-
ExportAdapter.prototype.addRelation = function(key, fromClassName,
246+
DatabaseController.prototype.addRelation = function(key, fromClassName,
247247
fromId, toId) {
248248
var doc = {
249249
relatedId: toId,
@@ -258,7 +258,7 @@ ExportAdapter.prototype.addRelation = function(key, fromClassName,
258258
// Removes a relation.
259259
// Returns a promise that resolves successfully iff the remove was
260260
// successful.
261-
ExportAdapter.prototype.removeRelation = function(key, fromClassName,
261+
DatabaseController.prototype.removeRelation = function(key, fromClassName,
262262
fromId, toId) {
263263
var doc = {
264264
relatedId: toId,
@@ -277,7 +277,7 @@ ExportAdapter.prototype.removeRelation = function(key, fromClassName,
277277
// acl: a list of strings. If the object to be updated has an ACL,
278278
// one of the provided strings must provide the caller with
279279
// write permissions.
280-
ExportAdapter.prototype.destroy = function(className, query, options = {}) {
280+
DatabaseController.prototype.destroy = function(className, query, options = {}) {
281281
var isMaster = !('acl' in options);
282282
var aclGroup = options.acl || [];
283283

@@ -320,7 +320,7 @@ ExportAdapter.prototype.destroy = function(className, query, options = {}) {
320320

321321
// Inserts an object into the database.
322322
// Returns a promise that resolves successfully iff the object saved.
323-
ExportAdapter.prototype.create = function(className, object, options) {
323+
DatabaseController.prototype.create = function(className, object, options) {
324324
var schema;
325325
var isMaster = !('acl' in options);
326326
var aclGroup = options.acl || [];
@@ -346,7 +346,7 @@ ExportAdapter.prototype.create = function(className, object, options) {
346346
// This should only be used for testing - use 'find' for normal code
347347
// to avoid Mongo-format dependencies.
348348
// Returns a promise that resolves to a list of items.
349-
ExportAdapter.prototype.mongoFind = function(className, query, options = {}) {
349+
DatabaseController.prototype.mongoFind = function(className, query, options = {}) {
350350
return this.collection(className).then((coll) => {
351351
return coll.find(query, options).toArray();
352352
});
@@ -355,7 +355,7 @@ ExportAdapter.prototype.mongoFind = function(className, query, options = {}) {
355355
// Deletes everything in the database matching the current collectionPrefix
356356
// Won't delete collections in the system namespace
357357
// Returns a promise.
358-
ExportAdapter.prototype.deleteEverything = function() {
358+
DatabaseController.prototype.deleteEverything = function() {
359359
this.schemaPromise = null;
360360

361361
return this.connect().then(() => {
@@ -390,7 +390,7 @@ function keysForQuery(query) {
390390

391391
// Returns a promise for a list of related ids given an owning id.
392392
// className here is the owning className.
393-
ExportAdapter.prototype.relatedIds = function(className, key, owningId) {
393+
DatabaseController.prototype.relatedIds = function(className, key, owningId) {
394394
var joinTable = '_Join:' + key + ':' + className;
395395
return this.collection(joinTable).then((coll) => {
396396
return coll.find({owningId: owningId}).toArray();
@@ -401,7 +401,7 @@ ExportAdapter.prototype.relatedIds = function(className, key, owningId) {
401401

402402
// Returns a promise for a list of owning ids given some related ids.
403403
// className here is the owning className.
404-
ExportAdapter.prototype.owningIds = function(className, key, relatedIds) {
404+
DatabaseController.prototype.owningIds = function(className, key, relatedIds) {
405405
var joinTable = '_Join:' + key + ':' + className;
406406
return this.collection(joinTable).then((coll) => {
407407
return coll.find({relatedId: {'$in': relatedIds}}).toArray();
@@ -414,7 +414,7 @@ ExportAdapter.prototype.owningIds = function(className, key, relatedIds) {
414414
// equal-to-pointer constraints on relation fields.
415415
// Returns a promise that resolves when query is mutated
416416
// TODO: this only handles one of these at a time - make it handle more
417-
ExportAdapter.prototype.reduceInRelation = function(className, query, schema) {
417+
DatabaseController.prototype.reduceInRelation = function(className, query, schema) {
418418
// Search for an in-relation or equal-to-relation
419419
for (var key in query) {
420420
if (query[key] &&
@@ -442,7 +442,7 @@ ExportAdapter.prototype.reduceInRelation = function(className, query, schema) {
442442

443443
// Modifies query so that it no longer has $relatedTo
444444
// Returns a promise that resolves when query is mutated
445-
ExportAdapter.prototype.reduceRelationKeys = function(className, query) {
445+
DatabaseController.prototype.reduceRelationKeys = function(className, query) {
446446
var relatedTo = query['$relatedTo'];
447447
if (relatedTo) {
448448
return this.relatedIds(
@@ -461,7 +461,7 @@ ExportAdapter.prototype.reduceRelationKeys = function(className, query) {
461461
// none, then build the geoindex.
462462
// This could be improved a lot but it's not clear if that's a good
463463
// idea. Or even if this behavior is a good idea.
464-
ExportAdapter.prototype.smartFind = function(coll, where, options) {
464+
DatabaseController.prototype.smartFind = function(coll, where, options) {
465465
return coll.find(where, options).toArray()
466466
.then((result) => {
467467
return result;
@@ -502,7 +502,7 @@ ExportAdapter.prototype.smartFind = function(coll, where, options) {
502502
// TODO: make userIds not needed here. The db adapter shouldn't know
503503
// anything about users, ideally. Then, improve the format of the ACL
504504
// arg to work like the others.
505-
ExportAdapter.prototype.find = function(className, query, options = {}) {
505+
DatabaseController.prototype.find = function(className, query, options = {}) {
506506
var mongoOptions = {};
507507
if (options.skip) {
508508
mongoOptions.skip = options.skip;
@@ -568,4 +568,4 @@ ExportAdapter.prototype.find = function(className, query, options = {}) {
568568
});
569569
};
570570

571-
module.exports = ExportAdapter;
571+
module.exports = DatabaseController;

src/DatabaseAdapter.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
// * destroy(className, query, options)
1414
// * This list is incomplete and the database process is not fully modularized.
1515
//
16-
// Default is ExportAdapter, which uses mongo.
16+
// Default is DatabaseController, which uses mongo at this time.
1717

18-
var ExportAdapter = require('./ExportAdapter');
19-
20-
var adapter = ExportAdapter;
18+
var adapter = require('./Controllers/DatabaseController');
2119
var dbConnections = {};
2220
var databaseURI = 'mongodb://localhost:27017/parse';
2321
var appDatabaseURIs = {};

src/Schema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// keeping it this way for now.
1111
//
1212
// In API-handling code, you should only use the Schema class via the
13-
// ExportAdapter. This will let us replace the schema logic for
13+
// DatabaseController. This will let us replace the schema logic for
1414
// different databases.
1515
// TODO: hide all schema logic inside the database adapter.
1616

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ addParseCloud();
4545

4646
// ParseServer works like a constructor of an express app.
4747
// The args that we understand are:
48-
// "databaseAdapter": a class like ExportAdapter providing create, find,
48+
// "databaseAdapter": a class like DatabaseController providing create, find,
4949
// update, and delete
5050
// "filesAdapter": a class like GridStoreAdapter providing create, get,
5151
// and delete

0 commit comments

Comments
 (0)