Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
49 changes: 49 additions & 0 deletions spec/ParseQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4517,4 +4517,53 @@ describe('Parse.Query testing', () => {
.then(done.fail)
.catch(() => done());
});

it('can add new config to existing config', async () => {
await request({
method: 'PUT',
url: 'http://localhost:8378/1/config',
json: true,
body: {
params: {
files: [{ __type: 'File', name: 'name', url: 'http://url' }],
},
},
headers: masterKeyHeaders,
});

await request({
method: 'PUT',
url: 'http://localhost:8378/1/config',
json: true,
body: {
params: { newConfig: 'good' },
},
headers: masterKeyHeaders,
});

const result = await Parse.Config.get();
equal(result.get('files')[0].toJSON(), {
__type: 'File',
name: 'name',
url: 'http://url',
});
equal(result.get('newConfig'), 'good');
});

it('can set object type key', async () => {
const data = { bar: true, baz: 100 };
const object = new TestObject();
object.set('objectField', data);
await object.save();

const query = new Parse.Query(TestObject);
let result = await query.get(object.id);
equal(result.get('objectField'), data);

object.set('objectField.baz', 50, { ignoreValidation: true });
await object.save();

result = await query.get(object.id);
equal(result.get('objectField'), { bar: true, baz: 50 });
});
});
22 changes: 20 additions & 2 deletions src/Adapters/Storage/Postgres/PostgresStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
const qs = `CREATE TABLE IF NOT EXISTS $1:name (${patternsArray.join()})`;
const values = [className, ...valuesArray];

debug(qs, values);
return conn.task('create-table', function*(t) {
try {
yield self._ensureSchemaCollectionExists(t);
Expand Down Expand Up @@ -1426,6 +1427,18 @@ export class PostgresStorageAdapter implements StorageAdapter {
schema = toPostgresSchema(schema);

const originalUpdate = { ...update };

// Set flag for dot notation fields
const dotNotationOptions = {};
Object.keys(update).forEach(fieldName => {
if (fieldName.indexOf('.') > -1) {
const components = fieldName.split('.');
const first = components.shift();
dotNotationOptions[first] = true;
} else {
dotNotationOptions[fieldName] = false;
}
});
update = handleDotFields(update);
// Resolve authData first,
// So we don't end up with multiple key updates
Expand Down Expand Up @@ -1615,13 +1628,18 @@ export class PostgresStorageAdapter implements StorageAdapter {
},
''
);
// Override Object
let updateObject = "'{}'::jsonb";

if (dotNotationOptions[fieldName]) {
// Merge Object
updateObject = `COALESCE($${index}:name, '{}'::jsonb)`;
}
updatePatterns.push(
`$${index}:name = ('{}'::jsonb ${deletePatterns} ${incrementPatterns} || $${index +
`$${index}:name = (${updateObject} ${deletePatterns} ${incrementPatterns} || $${index +
1 +
keysToDelete.length}::jsonb )`
);

values.push(fieldName, ...keysToDelete, JSON.stringify(fieldValue));
index += 2 + keysToDelete.length;
} else if (
Expand Down