From 7b3da8b744d8e0ff9a31866e873d6ea5d463dc60 Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Tue, 18 Dec 2018 12:11:24 -0600 Subject: [PATCH] PG: Fix updating numeric array (#5251) * PG: Fix updating numeric array * lint --- 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 e63c1105..230104f1 100644 --- a/spec/ParseQuery.spec.js +++ b/spec/ParseQuery.spec.js @@ -4566,4 +4566,27 @@ 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]; + 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 a59dc927..ca3b8b28 100644 --- a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js +++ b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js @@ -1657,6 +1657,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`