PG: Fix updating mixed array (#5552)
* PG: Fix updating mixed array * Revert "PG: Fix updating mixed array" This reverts commit 5a441413c083747d9e51767be7b2e9298bd4f8ba. * simple fix
This commit is contained in:
@@ -4637,4 +4637,23 @@ describe('Parse.Query testing', () => {
|
|||||||
const results = await query.find();
|
const results = await query.find();
|
||||||
equal(results[0].get('array'), data2);
|
equal(results[0].get('array'), data2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can update mixed array more than 100 elements', async () => {
|
||||||
|
const array = [0, 1.1, 'hello world', { foo: 'bar' }, null];
|
||||||
|
const obj = new TestObject({ array });
|
||||||
|
await obj.save();
|
||||||
|
|
||||||
|
const query = new Parse.Query(TestObject);
|
||||||
|
const result = await query.get(obj.id);
|
||||||
|
equal(result.get('array').length, 5);
|
||||||
|
|
||||||
|
for (let i = 0; i < 100; i += 1) {
|
||||||
|
array.push(i);
|
||||||
|
}
|
||||||
|
obj.set('array', array);
|
||||||
|
await obj.save();
|
||||||
|
|
||||||
|
const results = await query.find();
|
||||||
|
equal(results[0].get('array').length, 105);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1672,33 +1672,9 @@ export class PostgresStorageAdapter implements StorageAdapter {
|
|||||||
values.push(fieldName, fieldValue);
|
values.push(fieldName, fieldValue);
|
||||||
index += 2;
|
index += 2;
|
||||||
} else {
|
} else {
|
||||||
values.push(fieldName);
|
updatePatterns.push(`$${index}:name = $${index + 1}::jsonb`);
|
||||||
const buildSQLArray = fieldValue => {
|
values.push(fieldName, JSON.stringify(fieldValue));
|
||||||
let pattern = 'json_build_array(';
|
index += 2;
|
||||||
for (let i = 0; i < fieldValue.length; i += 1) {
|
|
||||||
const element = fieldValue[i];
|
|
||||||
let type = '';
|
|
||||||
if (Array.isArray(element)) {
|
|
||||||
pattern += buildSQLArray(element) + ',';
|
|
||||||
continue;
|
|
||||||
} else if (typeof element == 'object') {
|
|
||||||
type = '::json';
|
|
||||||
}
|
|
||||||
values.push(element);
|
|
||||||
pattern += `$${index + 1}${type},`;
|
|
||||||
index += 1;
|
|
||||||
}
|
|
||||||
// remove last comma
|
|
||||||
if (fieldValue.length > 0) {
|
|
||||||
pattern = pattern.slice(0, -1);
|
|
||||||
}
|
|
||||||
pattern += ')';
|
|
||||||
return pattern;
|
|
||||||
};
|
|
||||||
const sql = `$${index}:name = ${buildSQLArray(fieldValue)}`;
|
|
||||||
|
|
||||||
updatePatterns.push(sql);
|
|
||||||
index += 1;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debug('Not supported update', fieldName, fieldValue);
|
debug('Not supported update', fieldName, fieldValue);
|
||||||
|
|||||||
Reference in New Issue
Block a user