mirror of https://github.com/Fabio286/antares.git
feat: edit rows from tables without a primary key
This commit is contained in:
parent
574d493908
commit
5940b0b842
|
@ -78,12 +78,33 @@ export default (connections) => {
|
|||
else
|
||||
escapedParam = `"${sqlEscaper(params.content)}"`;
|
||||
|
||||
if (params.primary) {
|
||||
await connections[params.uid]
|
||||
.update({ [params.field]: `= ${escapedParam}` })
|
||||
.schema(params.schema)
|
||||
.from(params.table)
|
||||
.where({ [params.primary]: `= ${id}` })
|
||||
.run();
|
||||
}
|
||||
else {
|
||||
const { row } = params;
|
||||
reload = true;
|
||||
|
||||
for (const key in row) {
|
||||
if (typeof row[key] === 'string')
|
||||
row[key] = `'${row[key]}'`;
|
||||
|
||||
row[key] = `= ${row[key]}`;
|
||||
}
|
||||
|
||||
await connections[params.uid]
|
||||
.schema(params.schema)
|
||||
.update({ [params.field]: `= ${escapedParam}` })
|
||||
.from(params.table)
|
||||
.where(row)
|
||||
.limit(1)
|
||||
.run();
|
||||
}
|
||||
|
||||
return { status: 'success', response: { reload } };
|
||||
}
|
||||
|
@ -92,7 +113,7 @@ export default (connections) => {
|
|||
}
|
||||
});
|
||||
|
||||
ipcMain.handle('delete-table-rows', async (event, params) => { // TODO: check primary or try other
|
||||
ipcMain.handle('delete-table-rows', async (event, params) => {
|
||||
if (params.primary) {
|
||||
const idString = params.rows.map(row => typeof row[params.primary] === 'string'
|
||||
? `"${row[params.primary]}"`
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
class="tr"
|
||||
:class="{'selected': selectedRows.includes(row._id)}"
|
||||
@select-row="selectRow($event, row._id)"
|
||||
@update-field="updateField($event, getPrimaryValue(row))"
|
||||
@update-field="updateField($event, row)"
|
||||
@contextmenu="contextMenu"
|
||||
/>
|
||||
</template>
|
||||
|
@ -253,19 +253,18 @@ export default {
|
|||
refreshScroller () {
|
||||
this.resizeResults();
|
||||
},
|
||||
updateField (payload, id) {
|
||||
if (!this.primaryField)
|
||||
this.addNotification({ status: 'warning', message: this.$t('message.unableEditFieldWithoutPrimary') });
|
||||
else {
|
||||
updateField (payload, row) {
|
||||
delete row._id;
|
||||
|
||||
const params = {
|
||||
primary: this.primaryField.name,
|
||||
schema: this.getSchema(this.resultsetIndex),
|
||||
table: this.getTable(this.resultsetIndex),
|
||||
id,
|
||||
id: this.getPrimaryValue(row),
|
||||
row,
|
||||
...payload
|
||||
};
|
||||
this.$emit('update-field', params);
|
||||
}
|
||||
},
|
||||
deleteSelected () {
|
||||
const rows = this.localResults.filter(row => this.selectedRows.includes(row._id)).map(row => {
|
||||
|
|
Loading…
Reference in New Issue