From 6e40a934d6566d750186dc53373b6fe1a206b9f1 Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Tue, 18 Dec 2018 10:42:29 -0600 Subject: [PATCH 1/2] PG: Fix updating numeric array --- spec/ParseQuery.spec.js | 23 +++++++++++++++++++ .../Postgres/PostgresStorageAdapter.js | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/spec/ParseQuery.spec.js b/spec/ParseQuery.spec.js index 2c7325b858..1a8a181e60 100644 --- a/spec/ParseQuery.spec.js +++ b/spec/ParseQuery.spec.js @@ -4517,4 +4517,27 @@ describe('Parse.Query testing', () => { .then(done.fail) .catch(() => done()); }); + + it('can update numeric array', async () => { + const data1 = [0, 1.1, 1, -2, 3]; + const data2 = [0, 1.1, 1, -2, 3, 4]; + const obj1 = new TestObject(); + obj1.set('array', data1); + await obj1.save(); + equal(obj1.get('array'), data1); + + const query = new Parse.Query(TestObject); + query.equalTo('objectId', obj1.id); + + const result = await query.first(); + equal(result.get('array'), data1); + + result.set('array', data2); + equal(result.get('array'), data2); + await result.save(); + equal(result.get('array'), data2); + + const results = await query.find(); + equal(results[0].get('array'), data2); + }); }); diff --git a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js index 6c6a47020d..3a29074b40 100644 --- a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js +++ b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js @@ -1639,6 +1639,10 @@ export class PostgresStorageAdapter implements StorageAdapter { type = 'json'; break; } + if (typeof elt == 'number') { + type = 'numeric'; + break; + } } updatePatterns.push( `$${index}:name = array_to_json($${index + 1}::${type}[])::jsonb` From 8a5894b090606f278d1c7fbadf457a26d1b4fe20 Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Tue, 18 Dec 2018 11:00:27 -0600 Subject: [PATCH 2/2] lint --- spec/ParseQuery.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/ParseQuery.spec.js b/spec/ParseQuery.spec.js index 512c08b636..230104f182 100644 --- a/spec/ParseQuery.spec.js +++ b/spec/ParseQuery.spec.js @@ -4566,7 +4566,7 @@ describe('Parse.Query testing', () => { result = await query.get(object.id); equal(result.get('objectField'), { bar: true, baz: 50 }); }); - + it('can update numeric array', async () => { const data1 = [0, 1.1, 1, -2, 3]; const data2 = [0, 1.1, 1, -2, 3, 4];