Fix PG fails (#2957)
* Better support for arrays of objects * No transaction in class creation
This commit is contained in:
@@ -410,11 +410,8 @@ export class PostgresStorageAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createClass(className, schema) {
|
createClass(className, schema) {
|
||||||
return this._client.tx(t => {
|
return this.createTable(className, schema).then(() => {
|
||||||
const q1 = this.createTable(className, schema);
|
return this._client.none('INSERT INTO "_SCHEMA" ("className", "schema", "isParseClass") VALUES ($<className>, $<schema>, true)', { className, schema });
|
||||||
const q2 = this._client.none('INSERT INTO "_SCHEMA" ("className", "schema", "isParseClass") VALUES ($<className>, $<schema>, true)', { className, schema });
|
|
||||||
|
|
||||||
return t.batch([q1, q2]);
|
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return toParseSchema(schema)
|
return toParseSchema(schema)
|
||||||
@@ -895,7 +892,14 @@ export class PostgresStorageAdapter {
|
|||||||
if (expectedType === 'text[]') {
|
if (expectedType === 'text[]') {
|
||||||
updatePatterns.push(`$${index}:name = $${index + 1}::text[]`);
|
updatePatterns.push(`$${index}:name = $${index + 1}::text[]`);
|
||||||
} else {
|
} 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);
|
values.push(fieldName, fieldValue);
|
||||||
index += 2;
|
index += 2;
|
||||||
|
|||||||
Reference in New Issue
Block a user