Skip to content

Commit 0e78c28

Browse files
authored
Fix PG fails (#2957)
* Better support for arrays of objects * No transaction in class creation
1 parent 23b77f7 commit 0e78c28

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,11 +410,8 @@ export class PostgresStorageAdapter {
410410
}
411411

412412
createClass(className, schema) {
413-
return this._client.tx(t => {
414-
const q1 = this.createTable(className, schema);
415-
const q2 = this._client.none('INSERT INTO "_SCHEMA" ("className", "schema", "isParseClass") VALUES ($<className>, $<schema>, true)', { className, schema });
416-
417-
return t.batch([q1, q2]);
413+
return this.createTable(className, schema).then(() => {
414+
return this._client.none('INSERT INTO "_SCHEMA" ("className", "schema", "isParseClass") VALUES ($<className>, $<schema>, true)', { className, schema });
418415
})
419416
.then(() => {
420417
return toParseSchema(schema)
@@ -895,7 +892,14 @@ export class PostgresStorageAdapter {
895892
if (expectedType === 'text[]') {
896893
updatePatterns.push(`$${index}:name = $${index + 1}::text[]`);
897894
} else {
898-
updatePatterns.push(`$${index}:name = array_to_json($${index + 1}::text[])::jsonb`);
895+
let type = 'text';
896+
for (let elt of fieldValue) {
897+
if (typeof elt == 'object') {
898+
type = 'json';
899+
break;
900+
}
901+
}
902+
updatePatterns.push(`$${index}:name = array_to_json($${index + 1}::${type}[])::jsonb`);
899903
}
900904
values.push(fieldName, fieldValue);
901905
index += 2;

0 commit comments

Comments
 (0)