From 0e78c28146e4e907ba5944c466b7d4dfc37a4ac6 Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Fri, 28 Oct 2016 16:43:52 -0400 Subject: [PATCH] Fix PG fails (#2957) * Better support for arrays of objects * No transaction in class creation --- .../Storage/Postgres/PostgresStorageAdapter.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js index eef88d63..0e194752 100644 --- a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js +++ b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js @@ -410,11 +410,8 @@ export class PostgresStorageAdapter { } createClass(className, schema) { - return this._client.tx(t => { - const q1 = this.createTable(className, schema); - const q2 = this._client.none('INSERT INTO "_SCHEMA" ("className", "schema", "isParseClass") VALUES ($, $, true)', { className, schema }); - - return t.batch([q1, q2]); + return this.createTable(className, schema).then(() => { + return this._client.none('INSERT INTO "_SCHEMA" ("className", "schema", "isParseClass") VALUES ($, $, true)', { className, schema }); }) .then(() => { return toParseSchema(schema) @@ -895,7 +892,14 @@ export class PostgresStorageAdapter { if (expectedType === 'text[]') { updatePatterns.push(`$${index}:name = $${index + 1}::text[]`); } else { - updatePatterns.push(`$${index}:name = array_to_json($${index + 1}::text[])::jsonb`); + let type = 'text'; + for (let elt of fieldValue) { + if (typeof elt == 'object') { + type = 'json'; + break; + } + } + updatePatterns.push(`$${index}:name = array_to_json($${index + 1}::${type}[])::jsonb`); } values.push(fieldName, fieldValue); index += 2;