mirror of
https://github.com/Fabio286/antares.git
synced 2025-04-14 10:12:04 +02:00
fix: update or delete rows with more than one primary key
This commit is contained in:
parent
db47b4040a
commit
22a8c25717
@ -119,30 +119,31 @@ export default (connections) => {
|
|||||||
else
|
else
|
||||||
escapedParam = `'${sqlEscaper(params.content)}'`;
|
escapedParam = `'${sqlEscaper(params.content)}'`;
|
||||||
|
|
||||||
if (params.primary) {
|
if (params.primary) { // TODO: handle multiple primary
|
||||||
await connections[params.uid]
|
await connections[params.uid]
|
||||||
.update({ [params.field]: `= ${escapedParam}` })
|
.update({ [params.field]: `= ${escapedParam}` })
|
||||||
.schema(params.schema)
|
.schema(params.schema)
|
||||||
.from(params.table)
|
.from(params.table)
|
||||||
.where({ [params.primary]: `= ${id}` })
|
.where({ [params.primary]: `= ${id}` })
|
||||||
|
.limit(1)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const { row } = params;
|
const { orgRow } = params;
|
||||||
reload = true;
|
reload = true;
|
||||||
|
|
||||||
for (const key in row) {
|
for (const key in orgRow) {
|
||||||
if (typeof row[key] === 'string')
|
if (typeof orgRow[key] === 'string')
|
||||||
row[key] = `'${row[key]}'`;
|
orgRow[key] = `'${orgRow[key]}'`;
|
||||||
|
|
||||||
row[key] = `= ${row[key]}`;
|
orgRow[key] = `= ${orgRow[key]}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
await connections[params.uid]
|
await connections[params.uid]
|
||||||
.schema(params.schema)
|
.schema(params.schema)
|
||||||
.update({ [params.field]: `= ${escapedParam}` })
|
.update({ [params.field]: `= ${escapedParam}` })
|
||||||
.from(params.table)
|
.from(params.table)
|
||||||
.where(row)
|
.where(orgRow)
|
||||||
.limit(1)
|
.limit(1)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
@ -328,6 +328,8 @@ export class PostgreSQLClient extends AntaresCore {
|
|||||||
* @returns {Array}
|
* @returns {Array}
|
||||||
*/
|
*/
|
||||||
async getTableByIDs (ids) {
|
async getTableByIDs (ids) {
|
||||||
|
if (!ids) return;
|
||||||
|
|
||||||
const { rows } = await this.raw(`
|
const { rows } = await this.raw(`
|
||||||
SELECT relid AS tableid, relname, schemaname FROM pg_statio_all_tables WHERE relid IN (${ids})
|
SELECT relid AS tableid, relname, schemaname FROM pg_statio_all_tables WHERE relid IN (${ids})
|
||||||
UNION
|
UNION
|
||||||
@ -1206,7 +1208,7 @@ export class PostgreSQLClient extends AntaresCore {
|
|||||||
const orderByRaw = orderByArray.length ? `ORDER BY ${orderByArray.join(', ')} ` : '';
|
const orderByRaw = orderByArray.length ? `ORDER BY ${orderByArray.join(', ')} ` : '';
|
||||||
|
|
||||||
// LIMIT
|
// LIMIT
|
||||||
const limitRaw = this._query.limit.length ? `LIMIT ${this._query.limit.join(', ')} ` : '';
|
const limitRaw = selectArray.length && this._query.limit.length ? `LIMIT ${this._query.limit.join(', ')} ` : '';
|
||||||
|
|
||||||
return `${selectRaw}${updateRaw ? 'UPDATE' : ''}${insertRaw ? 'INSERT ' : ''}${this._query.delete ? 'DELETE ' : ''}${fromRaw}${updateRaw}${whereRaw}${groupByRaw}${orderByRaw}${limitRaw}${insertRaw}`;
|
return `${selectRaw}${updateRaw ? 'UPDATE' : ''}${insertRaw ? 'INSERT ' : ''}${this._query.delete ? 'DELETE ' : ''}${fromRaw}${updateRaw}${whereRaw}${groupByRaw}${orderByRaw}${limitRaw}${insertRaw}`;
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,12 @@ export default {
|
|||||||
return this.getWorkspace(this.connUid).breadcrumbs.schema;
|
return this.getWorkspace(this.connUid).breadcrumbs.schema;
|
||||||
},
|
},
|
||||||
primaryField () {
|
primaryField () {
|
||||||
return this.fields.filter(field => ['pri', 'uni'].includes(field.key))[0] || false;
|
const primaryFields = this.fields.filter(field => ['pri', 'uni'].includes(field.key));
|
||||||
|
|
||||||
|
if (primaryFields.length > 1 || !primaryFields.length)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return primaryFields[0];
|
||||||
},
|
},
|
||||||
isSortable () {
|
isSortable () {
|
||||||
return this.fields.every(field => field.name);
|
return this.fields.every(field => field.name);
|
||||||
@ -289,15 +294,17 @@ export default {
|
|||||||
this.resizeResults();
|
this.resizeResults();
|
||||||
},
|
},
|
||||||
updateField (payload, row) {
|
updateField (payload, row) {
|
||||||
const localRow = Object.assign({}, row);
|
const orgRow = this.localResults.find(lr => lr._id === row._id);
|
||||||
delete localRow._id;
|
delete row._id;
|
||||||
|
delete orgRow._id;
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
primary: this.primaryField.name,
|
primary: this.primaryField.name,
|
||||||
schema: this.getSchema(this.resultsetIndex),
|
schema: this.getSchema(this.resultsetIndex),
|
||||||
table: this.getTable(this.resultsetIndex),
|
table: this.getTable(this.resultsetIndex),
|
||||||
id: this.getPrimaryValue(localRow),
|
id: this.getPrimaryValue(orgRow),
|
||||||
localRow,
|
row,
|
||||||
|
orgRow,
|
||||||
...payload
|
...payload
|
||||||
};
|
};
|
||||||
this.$emit('update-field', params);
|
this.$emit('update-field', params);
|
||||||
@ -326,6 +333,7 @@ export default {
|
|||||||
table: this.getTable(this.resultsetIndex),
|
table: this.getTable(this.resultsetIndex),
|
||||||
id: this.getPrimaryValue(row),
|
id: this.getPrimaryValue(row),
|
||||||
row,
|
row,
|
||||||
|
orgRow: row,
|
||||||
field: this.selectedCell.field,
|
field: this.selectedCell.field,
|
||||||
content: null
|
content: null
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
@import "~spectre.css/src/_variables.scss";
|
@import "~spectre.css/src/variables";
|
||||||
@import "variables";
|
@import "variables";
|
||||||
@import "transitions";
|
@import "transitions";
|
||||||
@import "data-types";
|
@import "data-types";
|
||||||
@ -6,8 +6,8 @@
|
|||||||
@import "fake-tables";
|
@import "fake-tables";
|
||||||
@import "mdi-additions";
|
@import "mdi-additions";
|
||||||
@import "db-icons";
|
@import "db-icons";
|
||||||
@import "~spectre.css/src/spectre.scss";
|
@import "~spectre.css/src/spectre";
|
||||||
@import "~spectre.css/src/spectre-exp.scss";
|
@import "~spectre.css/src/spectre-exp";
|
||||||
|
|
||||||
body {
|
body {
|
||||||
user-select: none;
|
user-select: none;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user