mirror of https://github.com/Fabio286/antares.git
fix: insert files via add row option
This commit is contained in:
parent
2f1dfdc654
commit
3c6e818ba0
|
@ -25,7 +25,6 @@ Why am I developing an SQL client when there are a lot of thom on the market?-->
|
|||
|
||||
This is a roadmap with major features will come in near future.
|
||||
|
||||
- Options to insert new database records.
|
||||
- Improvements of query editor area.
|
||||
- Multiple query tabs.
|
||||
- Tables management (add/edit/delete).
|
||||
|
|
|
@ -235,10 +235,10 @@ export class AntaresConnector {
|
|||
for (const key in fields) {
|
||||
if (fields[key] === null) continue;
|
||||
fieldsList.push(key);
|
||||
valueList.push(typeof fields[key] === 'number' ? fields[key] : `"${fields[key]}"`);
|
||||
valueList.push(fields[key]);
|
||||
}
|
||||
|
||||
insertRaw = ` (${fieldsList.join(',')}) VALUES (${valueList.join(',')}) `;
|
||||
insertRaw = `(${fieldsList.join(', ')}) VALUES (${valueList.join(', ')}) `;
|
||||
}
|
||||
|
||||
const groupByArray = this._query.groupBy.reduce(this._reducer, []);
|
||||
|
|
|
@ -51,12 +51,36 @@ export default class {
|
|||
.run();
|
||||
}
|
||||
|
||||
static async insertTableRows (connection, params) { // Prepare every field like updateTableCell method
|
||||
static async insertTableRows (connection, params) {
|
||||
const insertObj = {};
|
||||
console.log(params);
|
||||
for (const key in params.row) {
|
||||
const type = params.fields[key];
|
||||
let escapedParam;
|
||||
|
||||
if (NUMBER.includes(type))
|
||||
escapedParam = params.row[key];
|
||||
else if ([...TEXT, ...LONG_TEXT].includes(type))
|
||||
escapedParam = `"${sqlEscaper(params.row[key])}"`;
|
||||
else if (BLOB.includes(type)) {
|
||||
if (params.row[key]) {
|
||||
const fileBlob = fs.readFileSync(params.row[key]);
|
||||
escapedParam = `0x${fileBlob.toString('hex')}`;
|
||||
}
|
||||
else
|
||||
escapedParam = '""';
|
||||
}
|
||||
else
|
||||
escapedParam = `"${sqlEscaper(params.row[key])}"`;
|
||||
|
||||
insertObj[key] = escapedParam;
|
||||
}
|
||||
|
||||
for (let i = 0; i < params.repeat; i++) {
|
||||
await connection
|
||||
.schema(params.schema)
|
||||
.into(params.table)
|
||||
.insert(params.row)
|
||||
.insert(insertObj)
|
||||
.run();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,14 @@
|
|||
:disabled="fieldsToExclude.includes(field.name)"
|
||||
:tabindex="key+1"
|
||||
>
|
||||
<input
|
||||
v-else-if="inputProps(field).type === 'file'"
|
||||
class="form-input"
|
||||
type="file"
|
||||
:disabled="fieldsToExclude.includes(field.name)"
|
||||
:tabindex="key+1"
|
||||
@change="filesChange($event,field.name)"
|
||||
>
|
||||
<input
|
||||
v-else
|
||||
v-model="localRow[field.name]"
|
||||
|
@ -148,7 +156,7 @@ export default {
|
|||
fieldDefault = field.default;
|
||||
|
||||
if (DATETIME.includes(field.type)) {
|
||||
if (field.default && field.default.includes('current_timestamp')) {
|
||||
if (field.default && field.default.toLowerCase().includes('current_timestamp')) {
|
||||
let datePrecision = '';
|
||||
for (let i = 0; i < field.datePrecision; i++)
|
||||
datePrecision += i === 0 ? '.S' : 'S';
|
||||
|
@ -175,6 +183,13 @@ export default {
|
|||
Object.keys(rowToInsert).forEach(key => {
|
||||
if (this.fieldsToExclude.includes(key))
|
||||
delete rowToInsert[key];
|
||||
if (typeof rowToInsert[key] === 'undefined')
|
||||
delete rowToInsert[key];
|
||||
});
|
||||
|
||||
const fieldTypes = {};
|
||||
this.fields.forEach(field => {
|
||||
fieldTypes[field.name] = field.type;
|
||||
});
|
||||
|
||||
try {
|
||||
|
@ -183,7 +198,8 @@ export default {
|
|||
schema: this.workspace.breadcrumbs.schema,
|
||||
table: this.workspace.breadcrumbs.table,
|
||||
row: rowToInsert,
|
||||
repeat: this.nInserts
|
||||
repeat: this.nInserts,
|
||||
fields: fieldTypes
|
||||
});
|
||||
|
||||
if (status === 'success') {
|
||||
|
@ -249,6 +265,12 @@ export default {
|
|||
this.fieldsToExclude = this.fieldsToExclude.filter(f => f !== field.name);
|
||||
else
|
||||
this.fieldsToExclude = [...this.fieldsToExclude, field.name];
|
||||
},
|
||||
filesChange (event, field) {
|
||||
const { files } = event.target;
|
||||
if (!files.length) return;
|
||||
|
||||
this.localRow[field] = files[0].path;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -47,7 +47,9 @@
|
|||
@hide="hideEditorModal"
|
||||
>
|
||||
<template :slot="'header'">
|
||||
{{ $t('word.edit') }} "{{ editingField }}"
|
||||
<div class="d-flex">
|
||||
<i class="mdi mdi-24px mdi-playlist-edit mr-1" /> {{ $t('word.edit') }} "{{ editingField }}"
|
||||
</div>
|
||||
</template>
|
||||
<div :slot="'body'">
|
||||
<div class="mb-2">
|
||||
|
@ -71,7 +73,9 @@
|
|||
@hide="hideEditorModal"
|
||||
>
|
||||
<template :slot="'header'">
|
||||
{{ $t('word.edit') }} "{{ editingField }}"
|
||||
<div class="d-flex">
|
||||
<i class="mdi mdi-24px mdi-playlist-edit mr-1" /> {{ $t('word.edit') }} "{{ editingField }}"
|
||||
</div>
|
||||
</template>
|
||||
<div :slot="'body'">
|
||||
<div class="mb-2">
|
||||
|
@ -299,7 +303,7 @@ export default {
|
|||
}
|
||||
|
||||
// Inline editable fields
|
||||
this.editingContent = this.$options.filters.typeFormat(this.originalContent, type);
|
||||
this.editingContent = this.$options.filters.typeFormat(this.originalContent, type, this.fieldPrecision(field));
|
||||
this.$nextTick(() => { // Focus on input
|
||||
event.target.blur();
|
||||
|
||||
|
|
Loading…
Reference in New Issue