mirror of https://github.com/Fabio286/antares.git
feat(MySQL): ENUM and SET fields support, closes #61
This commit is contained in:
parent
9dfe7cca22
commit
bebba64d06
|
@ -277,13 +277,6 @@ module.exports = [
|
|||
{
|
||||
group: 'other',
|
||||
types: [
|
||||
{
|
||||
name: 'UNKNOWN',
|
||||
length: false,
|
||||
collation: false,
|
||||
unsigned: false,
|
||||
zerofill: false
|
||||
},
|
||||
{
|
||||
name: 'ENUM',
|
||||
length: true,
|
||||
|
@ -299,5 +292,17 @@ module.exports = [
|
|||
zerofill: false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
group: 'unknown',
|
||||
types: [
|
||||
{
|
||||
name: 'UNKNOWN',
|
||||
length: false,
|
||||
collation: false,
|
||||
unsigned: false,
|
||||
zerofill: false
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
|
|
@ -310,6 +310,9 @@ export class MySQLClient extends AntaresCore {
|
|||
return rows.map(field => {
|
||||
let numLength = field.COLUMN_TYPE.match(/int\(([^)]+)\)/);
|
||||
numLength = numLength ? +numLength.pop() : null;
|
||||
const enumValues = /(enum|set)/.test(field.COLUMN_TYPE)
|
||||
? field.COLUMN_TYPE.match(/\(([^)]+)\)/)[0].slice(1, -1)
|
||||
: null;
|
||||
|
||||
return {
|
||||
name: field.COLUMN_NAME,
|
||||
|
@ -319,6 +322,7 @@ export class MySQLClient extends AntaresCore {
|
|||
table: field.TABLE_NAME,
|
||||
numPrecision: field.NUMERIC_PRECISION,
|
||||
numLength,
|
||||
enumValues,
|
||||
datePrecision: field.DATETIME_PRECISION,
|
||||
charLength: field.CHARACTER_MAXIMUM_LENGTH,
|
||||
nullable: field.IS_NULLABLE.includes('YES'),
|
||||
|
@ -1116,7 +1120,7 @@ export class MySQLClient extends AntaresCore {
|
|||
// CHANGE FIELDS
|
||||
changes.forEach(change => {
|
||||
const typeInfo = this._getTypeInfo(change.type);
|
||||
const length = typeInfo.length ? change.numLength || change.charLength || change.datePrecision : false;
|
||||
const length = typeInfo.length ? change.enumValues || change.numLength || change.charLength || change.datePrecision : false;
|
||||
|
||||
alterColumns.push(`CHANGE COLUMN \`${change.orgName}\` \`${change.name}\`
|
||||
${change.type.toUpperCase()}${length ? `(${length})` : ''}
|
||||
|
@ -1190,7 +1194,7 @@ export class MySQLClient extends AntaresCore {
|
|||
* @memberof MySQLClient
|
||||
*/
|
||||
async truncateTable (params) {
|
||||
const sql = `TRUNCATE TABLE \`${params.table}\``;
|
||||
const sql = `TRUNCATE TABLE \`${this._schema}\`.\`${params.table}\``;
|
||||
return await this.raw(sql);
|
||||
}
|
||||
|
||||
|
@ -1201,7 +1205,7 @@ export class MySQLClient extends AntaresCore {
|
|||
* @memberof MySQLClient
|
||||
*/
|
||||
async dropTable (params) {
|
||||
const sql = `DROP TABLE \`${params.table}\``;
|
||||
const sql = `DROP TABLE \`${this._schema}\`.\`${params.table}\``;
|
||||
return await this.raw(sql);
|
||||
}
|
||||
|
||||
|
|
|
@ -98,6 +98,15 @@
|
|||
>
|
||||
{{ localLength }}
|
||||
</span>
|
||||
<input
|
||||
v-else-if="localRow.enumValues"
|
||||
ref="editField"
|
||||
v-model="editingContent"
|
||||
type="text"
|
||||
autofocus
|
||||
class="editable-field px-2"
|
||||
@blur="editOFF"
|
||||
>
|
||||
<input
|
||||
v-else
|
||||
ref="editField"
|
||||
|
@ -352,7 +361,7 @@ export default {
|
|||
getWorkspace: 'workspaces/getWorkspace'
|
||||
}),
|
||||
localLength () {
|
||||
return this.localRow.numLength || this.localRow.charLength || this.localRow.datePrecision || this.localRow.numPrecision || 0;
|
||||
return this.localRow.enumValues || this.localRow.numLength || this.localRow.charLength || this.localRow.datePrecision || this.localRow.numPrecision || 0;
|
||||
},
|
||||
fieldType () {
|
||||
const fieldType = this.dataTypes.reduce((acc, group) => [...acc, ...group.types], []).filter(type =>
|
||||
|
@ -458,14 +467,21 @@ export default {
|
|||
editON (event, content, field) {
|
||||
if (field === 'length') {
|
||||
if (['integer', 'float', 'binary', 'spatial'].includes(this.fieldType.group)) this.editingField = 'numLength';
|
||||
if (['string', 'other'].includes(this.fieldType.group)) this.editingField = 'charLength';
|
||||
if (['time'].includes(this.fieldType.group)) this.editingField = 'datePrecision';
|
||||
else if (['string', 'unknown'].includes(this.fieldType.group)) this.editingField = 'charLength';
|
||||
else if (['other'].includes(this.fieldType.group)) this.editingField = 'enumValues';
|
||||
else if (['time'].includes(this.fieldType.group)) this.editingField = 'datePrecision';
|
||||
}
|
||||
else
|
||||
this.editingField = field;
|
||||
|
||||
this.editingContent = content;
|
||||
this.originalContent = content;
|
||||
if (this.localRow.enumValues && field === 'length') {
|
||||
this.editingContent = this.localRow.enumValues;
|
||||
this.originalContent = this.localRow.enumValues;
|
||||
}
|
||||
else {
|
||||
this.editingContent = content;
|
||||
this.originalContent = content;
|
||||
}
|
||||
|
||||
const obj = { [field]: true };
|
||||
this.isInlineEditor = { ...this.isInlineEditor, ...obj };
|
||||
|
|
|
@ -43,6 +43,16 @@
|
|||
<option>true</option>
|
||||
<option>false</option>
|
||||
</select>
|
||||
<select
|
||||
v-else-if="enumArray"
|
||||
v-model="editingContent"
|
||||
class="form-select small-select editable-field"
|
||||
@blur="editOFF"
|
||||
>
|
||||
<option v-for="value in enumArray" :key="value">
|
||||
{{ value }}
|
||||
</option>
|
||||
</select>
|
||||
<input
|
||||
v-else
|
||||
ref="editField"
|
||||
|
@ -336,6 +346,11 @@ export default {
|
|||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
enumArray () {
|
||||
if (this.fields[this.editingField].enumValues)
|
||||
return this.fields[this.editingField].enumValues.replaceAll('\'', '').split(',');
|
||||
return false;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
|
|
Loading…
Reference in New Issue