Skip to content

Postgres: $all, $and CLP and more #2551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Aug 20, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions spec/ParseQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2488,8 +2488,7 @@ describe('Parse.Query testing', () => {
})
})

// TODO: tricky with PG with non existant columns
it_exclude_dbs(['postgres'])('query with two OR subqueries (regression test #1259)', done => {
it('query with two OR subqueries (regression test #1259)', done => {
let relatedObject = new Parse.Object('Class2');
relatedObject.save().then(relatedObject => {
let anObject = new Parse.Object('Class1');
Expand Down
4 changes: 2 additions & 2 deletions spec/PushController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ describe('PushController', () => {
})
});

it_exclude_dbs(['postgres'])('should support full RESTQuery for increment', (done) => {
it('should support full RESTQuery for increment', (done) => {
var payload = {data: {
alert: "Hello World!",
badge: 'Increment',
Expand Down Expand Up @@ -392,7 +392,7 @@ describe('PushController', () => {
pushController.sendPush(payload, where, config, auth).then((result) => {
done();
}).catch((err) => {
fail('should not fail');
jfail(err);
done();
});
});
Expand Down
23 changes: 15 additions & 8 deletions src/Adapters/Storage/Postgres/PostgresStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ const buildWhereClause = ({ schema, query, index }) => {
&& schema.fields[fieldName].type === 'Array';
let initialPatternsLength = patterns.length;
let fieldValue = query[fieldName];

// nothingin the schema, it's gonna blow up
if (!schema.fields[fieldName]) {
// as it won't exist
if (fieldValue.$exists === false) {
continue;
}
}

if (fieldName.indexOf('.') >= 0) {
let components = fieldName.split('.').map((cmpt, index) => {
if (index == 0) {
Expand Down Expand Up @@ -715,16 +724,15 @@ export class PostgresStorageAdapter {
}
});
}
// Return value not currently well specified.
findOneAndUpdate(className, schema, query, update) {
debug('findOneAndUpdate', className, query, update);
return this.updateObjectsByQuery(className, schema, query, update).then((val) => val[0]);
}

// Apply the update to all objects that match the given Parse Query.
updateObjectsByQuery(className, schema, query, update) {
debug('updateObjectsByQuery', className, query, update);
return this.findOneAndUpdate(className, schema, query, update);
}

// Return value not currently well specified.
findOneAndUpdate(className, schema, query, update) {
debug('findOneAndUpdate', className, query, update);
let conditionPatterns = [];
let updatePatterns = [];
let values = [className]
Expand Down Expand Up @@ -850,8 +858,7 @@ export class PostgresStorageAdapter {

let qs = `UPDATE $1:name SET ${updatePatterns.join(',')} WHERE ${where.pattern} RETURNING *`;
debug('update: ', qs, values);
return this._client.any(qs, values)
.then(val => val[0]); // TODO: This is unsafe, verification is needed, or a different query method;
return this._client.any(qs, values); // TODO: This is unsafe, verification is needed, or a different query method;
}

// Hopefully, we can get rid of this. It's only used for config and hooks.
Expand Down