Fix PG fails (#2957)

* Better support for arrays of objects

* No transaction in class creation
This commit is contained in:
Florent Vilmart
2016-10-28 16:43:52 -04:00
committed by GitHub
parent 23b77f7261
commit 0e78c28146

View File

@@ -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 ($<className>, $<schema>, 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 ($<className>, $<schema>, 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;