Incorporate vitaly-t changes (#2085)

This commit is contained in:
Drew
2016-06-16 19:34:00 -07:00
committed by GitHub
parent 9d078003a6
commit c37a4ea1a1

View File

@@ -104,11 +104,11 @@ export class PostgresStorageAdapter {
}; };
classExists(name) { classExists(name) {
return Promise.reject('Not implented yet.') return Promise.reject('Not implemented yet.')
} }
setClassLevelPermissions(className, CLPs) { setClassLevelPermissions(className, CLPs) {
return Promise.reject('Not implented yet.') return Promise.reject('Not implemented yet.')
} }
createClass(className, schema) { createClass(className, schema) {
@@ -136,7 +136,7 @@ export class PostgresStorageAdapter {
} }
addFieldIfNotExists(className, fieldName, type) { addFieldIfNotExists(className, fieldName, type) {
// TODO: Doing this in a transaction might be a good idea. // TODO: Must be re-done into a transaction!
return this._client.query('ALTER TABLE $<className:name> ADD COLUMN $<fieldName:name> $<postgresType:raw>', { className, fieldName, postgresType: parseTypeToPostgresType(type) }) return this._client.query('ALTER TABLE $<className:name> ADD COLUMN $<fieldName:name> $<postgresType:raw>', { className, fieldName, postgresType: parseTypeToPostgresType(type) })
.catch(error => { .catch(error => {
if (error.code === PostgresRelationDoesNotExistError) { if (error.code === PostgresRelationDoesNotExistError) {
@@ -165,10 +165,10 @@ export class PostgresStorageAdapter {
// Drops a collection. Resolves with true if it was a Parse Schema (eg. _User, Custom, etc.) // Drops a collection. Resolves with true if it was a Parse Schema (eg. _User, Custom, etc.)
// and resolves with false if it wasn't (eg. a join table). Rejects if deletion was impossible. // and resolves with false if it wasn't (eg. a join table). Rejects if deletion was impossible.
deleteClass(className) { deleteClass(className) {
return Promise.reject('Not implented yet.') return Promise.reject('Not implemented yet.')
} }
// Delete all data known to this adatper. Used for testing. // Delete all data known to this adapter. Used for testing.
deleteAllClasses() { deleteAllClasses() {
return this._client.query('SELECT "className" FROM "_SCHEMA"') return this._client.query('SELECT "className" FROM "_SCHEMA"')
.then(results => { .then(results => {
@@ -192,29 +192,21 @@ export class PostgresStorageAdapter {
// deleted do not exist, this function should return successfully anyways. Checking for // deleted do not exist, this function should return successfully anyways. Checking for
// attempts to delete non-existent fields is the responsibility of Parse Server. // attempts to delete non-existent fields is the responsibility of Parse Server.
// Pointer field names are passed for legacy reasons: the original mongo
// format stored pointer field names differently in the database, and therefore
// needed to know the type of the field before it could delete it. Future database
// adatpers should ignore the pointerFieldNames argument. All the field names are in
// fieldNames, they show up additionally in the pointerFieldNames database for use
// by the mongo adapter, which deals with the legacy mongo format.
// This function is not obligated to delete fields atomically. It is given the field // This function is not obligated to delete fields atomically. It is given the field
// names in a list so that databases that are capable of deleting fields atomically // names in a list so that databases that are capable of deleting fields atomically
// may do so. // may do so.
// Returns a Promise. // Returns a Promise.
deleteFields(className, schema, fieldNames) { deleteFields(className, schema, fieldNames) {
return Promise.reject('Not implented yet.') return Promise.reject('Not implemented yet.')
} }
// Return a promise for all schemas known to this adapter, in Parse format. In case the // Return a promise for all schemas known to this adapter, in Parse format. In case the
// schemas cannot be retrieved, returns a promise that rejects. Rquirements for the // schemas cannot be retrieved, returns a promise that rejects. Requirements for the
// rejection reason are TBD. // rejection reason are TBD.
getAllClasses() { getAllClasses() {
return this._ensureSchemaCollectionExists() return this._ensureSchemaCollectionExists()
.then(() => this._client.query('SELECT * FROM "_SCHEMA"')) .then(() => this._client.map('SELECT * FROM "_SCHEMA"'), null, row => ({ className: row.className, ...row.schema }));
.then(results => results.map(result => ({ className: result.className, ...result.schema })))
} }
// Return a promise for the schema with the given name, in Parse format. If // Return a promise for the schema with the given name, in Parse format. If
@@ -280,7 +272,7 @@ export class PostgresStorageAdapter {
// Apply the update to all objects that match the given Parse Query. // Apply the update to all objects that match the given Parse Query.
updateObjectsByQuery(className, schema, query, update) { updateObjectsByQuery(className, schema, query, update) {
return Promise.reject('Not implented yet.') return Promise.reject('Not implemented yet.')
} }
// Return value not currently well specified. // Return value not currently well specified.
@@ -310,14 +302,12 @@ export class PostgresStorageAdapter {
let qs = `UPDATE $1:name SET ${updatePatterns.join(',')} WHERE ${where.pattern} RETURNING *`; let qs = `UPDATE $1:name SET ${updatePatterns.join(',')} WHERE ${where.pattern} RETURNING *`;
return this._client.query(qs, values) return this._client.query(qs, values)
.then(val => { .then(val => val[0]); // TODO: This is unsafe, verification is needed, or a different query method;
return val[0];
})
} }
// Hopefully we can get rid of this. It's only used for config and hooks. // Hopefully, we can get rid of this. It's only used for config and hooks.
upsertOneObject(className, schema, query, update) { upsertOneObject(className, schema, query, update) {
return Promise.reject('Not implented yet.') return Promise.reject('Not implemented yet.')
} }
find(className, schema, query, { skip, limit, sort }) { find(className, schema, query, { skip, limit, sort }) {
@@ -369,9 +359,9 @@ export class PostgresStorageAdapter {
return this._client.query(qs,[className, constraintName, ...fieldNames]) return this._client.query(qs,[className, constraintName, ...fieldNames])
} }
// Executs a count. // Executes a count.
count(className, schema, query) { count(className, schema, query) {
return Promise.reject('Not implented yet.') return Promise.reject('Not implemented yet.')
} }
} }