PG: Support for multiple projection in aggregate (#4469)

This commit is contained in:
Diamond Lewis
2017-12-29 11:39:16 -06:00
committed by Vitaly Tomilov
parent 6ba939994d
commit 04f8673edd
2 changed files with 38 additions and 19 deletions

View File

@@ -254,7 +254,8 @@ describe('Parse.Query Aggregate testing', () => {
rp.get(Parse.serverURL + '/aggregate/TestObject', options) rp.get(Parse.serverURL + '/aggregate/TestObject', options)
.then((resp) => { .then((resp) => {
resp.results.forEach((result) => { resp.results.forEach((result) => {
expect(result.name !== undefined).toBe(true); expect(result.objectId).not.toBe(undefined);
expect(result.name).not.toBe(undefined);
expect(result.sender).toBe(undefined); expect(result.sender).toBe(undefined);
expect(result.size).toBe(undefined); expect(result.size).toBe(undefined);
expect(result.score).toBe(undefined); expect(result.score).toBe(undefined);
@@ -263,6 +264,25 @@ describe('Parse.Query Aggregate testing', () => {
}).catch(done.fail); }).catch(done.fail);
}); });
it('multiple project query', (done) => {
const options = Object.assign({}, masterKeyOptions, {
body: {
project: { name: 1, score: 1, sender: 1 },
}
});
rp.get(Parse.serverURL + '/aggregate/TestObject', options)
.then((resp) => {
resp.results.forEach((result) => {
expect(result.objectId).not.toBe(undefined);
expect(result.name).not.toBe(undefined);
expect(result.score).not.toBe(undefined);
expect(result.sender).not.toBe(undefined);
expect(result.size).toBe(undefined);
});
done();
}).catch(done.fail);
});
it('project with group query', (done) => { it('project with group query', (done) => {
const options = Object.assign({}, masterKeyOptions, { const options = Object.assign({}, masterKeyOptions, {
body: { body: {

View File

@@ -762,7 +762,7 @@ export class PostgresStorageAdapter {
throw error; throw error;
} }
// Column already exists, created by other request. Carry on to see if it's the right type. // Column already exists, created by other request. Carry on to see if it's the right type.
}; }
} else { } else {
yield t.none('CREATE TABLE IF NOT EXISTS $<joinTable:name> ("relatedId" varChar(120), "owningId" varChar(120), PRIMARY KEY("relatedId", "owningId") )', {joinTable: `_Join:${fieldName}:${className}`}); yield t.none('CREATE TABLE IF NOT EXISTS $<joinTable:name> ("relatedId" varChar(120), "owningId" varChar(120), PRIMARY KEY("relatedId", "owningId") )', {joinTable: `_Join:${fieldName}:${className}`});
} }
@@ -1500,7 +1500,6 @@ export class PostgresStorageAdapter {
columns.push(`AVG(${transformAggregateField(value.$avg)}) AS "${field}"`); columns.push(`AVG(${transformAggregateField(value.$avg)}) AS "${field}"`);
} }
} }
columns.join();
} else { } else {
columns.push('*'); columns.push('*');
} }
@@ -1546,7 +1545,7 @@ export class PostgresStorageAdapter {
} }
} }
const qs = `SELECT ${columns} FROM $1:name ${wherePattern} ${sortPattern} ${limitPattern} ${skipPattern} ${groupPattern}`; const qs = `SELECT ${columns.join()} FROM $1:name ${wherePattern} ${sortPattern} ${limitPattern} ${skipPattern} ${groupPattern}`;
debug(qs, values); debug(qs, values);
return this._client.map(qs, values, a => this.postgresObjectToParseObject(className, a, schema)) return this._client.map(qs, values, a => this.postgresObjectToParseObject(className, a, schema))
.then(results => { .then(results => {