mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-02 15:30:25 +08:00
refactor: dbms
This commit is contained in:
@@ -97,8 +97,8 @@
|
||||
<el-col :span="9">
|
||||
<el-form-item label="扩展名: ">
|
||||
<el-radio-group v-model="exportDialog.extName">
|
||||
<el-radio label="sql" />
|
||||
<el-radio label="gzip" />
|
||||
<el-radio label="sql" value="sql" />
|
||||
<el-radio label="gzip" value="gzip" />
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
@@ -518,7 +518,7 @@ watch(
|
||||
value: defaultValue,
|
||||
length: a.showLength,
|
||||
numScale: a.showScale,
|
||||
notNull: a.nullable !== 'YES',
|
||||
notNull: !a.nullable,
|
||||
pri: a.isPrimaryKey,
|
||||
auto_increment: a.isIdentity /*a.extra?.indexOf('auto_increment') > -1*/,
|
||||
remark: a.columnComment,
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
</template>
|
||||
<el-form-item label="导出内容: ">
|
||||
<el-radio-group v-model="dumpInfo.type">
|
||||
<el-radio :label="1" size="small">结构</el-radio>
|
||||
<el-radio :label="2" size="small">数据</el-radio>
|
||||
<el-radio :label="3" size="small">结构+数据</el-radio>
|
||||
<el-radio :value="1" size="small">结构</el-radio>
|
||||
<el-radio :value="2" size="small">数据</el-radio>
|
||||
<el-radio :value="3" size="small">结构+数据</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
|
||||
@@ -82,7 +82,7 @@
|
||||
<el-dialog width="40%" :title="`${chooseTableName} 字段信息`" v-model="columnDialog.visible">
|
||||
<el-table border stripe :data="columnDialog.columns" size="small">
|
||||
<el-table-column prop="columnName" label="名称" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column width="120" prop="columnType" label="类型" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column width="120" prop="showDataType" label="类型" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column width="80" prop="nullable" label="是否可为空" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column prop="columnComment" label="备注" show-overflow-tooltip> </el-table-column>
|
||||
</el-table>
|
||||
@@ -98,8 +98,8 @@
|
||||
</el-table>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog width="55%" :title="`${chooseTableName} Create-DDL`" v-model="ddlDialog.visible">
|
||||
<el-input disabled type="textarea" :autosize="{ minRows: 15, maxRows: 30 }" v-model="ddlDialog.ddl" size="small"> </el-input>
|
||||
<el-dialog width="55%" :title="`'${chooseTableName}' DDL`" v-model="ddlDialog.visible">
|
||||
<monaco-editor height="400px" language="sql" v-model="ddlDialog.ddl" :options="{ readOnly: true }" />
|
||||
</el-dialog>
|
||||
|
||||
<db-table-op
|
||||
@@ -126,7 +126,10 @@ import SqlExecBox from '../sqleditor/SqlExecBox';
|
||||
import config from '@/common/config';
|
||||
import { joinClientParams } from '@/common/request';
|
||||
import { isTrue } from '@/common/assert';
|
||||
import { compatibleMysql, editDbTypes } from '../../dialect/index';
|
||||
import { compatibleMysql, editDbTypes, getDbDialect } from '../../dialect/index';
|
||||
import { DbInst } from '../../db';
|
||||
import MonacoEditor from '@/components/monaco/MonacoEditor.vue';
|
||||
import { format as sqlFormatter } from 'sql-formatter';
|
||||
|
||||
const DbTableOp = defineAsyncComponent(() => import('./DbTableOp.vue'));
|
||||
|
||||
@@ -275,11 +278,13 @@ const dump = (db: string) => {
|
||||
|
||||
const showColumns = async (row: any) => {
|
||||
state.chooseTableName = row.tableName;
|
||||
state.columnDialog.columns = await dbApi.columnMetadata.request({
|
||||
const columns = await dbApi.columnMetadata.request({
|
||||
id: props.dbId,
|
||||
db: props.db,
|
||||
tableName: row.tableName,
|
||||
});
|
||||
DbInst.initColumns(columns);
|
||||
state.columnDialog.columns = columns;
|
||||
|
||||
state.columnDialog.visible = true;
|
||||
};
|
||||
@@ -302,7 +307,8 @@ const showCreateDdl = async (row: any) => {
|
||||
db: props.db,
|
||||
tableName: row.tableName,
|
||||
});
|
||||
state.ddlDialog.ddl = res;
|
||||
|
||||
state.ddlDialog.ddl = sqlFormatter(res, { language: getDbDialect(props.dbType).getInfo().formatSqlDialect });
|
||||
state.ddlDialog.visible = true;
|
||||
};
|
||||
|
||||
|
||||
@@ -251,8 +251,8 @@
|
||||
</el-form-item>
|
||||
<el-form-item prop="type" label="类型">
|
||||
<el-radio-group v-model="createFileDialog.type">
|
||||
<el-radio label="d">文件夹</el-radio>
|
||||
<el-radio label="-">文件</el-radio>
|
||||
<el-radio value="d" label="d">文件夹</el-radio>
|
||||
<el-radio value="-" label="-">文件</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</div>
|
||||
|
||||
@@ -69,7 +69,7 @@ type Column struct {
|
||||
IsPrimaryKey bool `json:"isPrimaryKey"` // 是否为主键
|
||||
IsIdentity bool `json:"isIdentity"` // 是否自增
|
||||
ColumnDefault string `json:"columnDefault"` // 默认值
|
||||
Nullable string `json:"nullable"` // 是否可为null
|
||||
Nullable bool `json:"nullable"` // 是否可为null
|
||||
CharMaxLength int `json:"charMaxLength"` // 字符最大长度
|
||||
NumPrecision int `json:"numPrecision"` // 精度(总数字位数)
|
||||
NumScale int `json:"numScale"` // 小数点位数
|
||||
|
||||
@@ -105,7 +105,7 @@ func (dd *DMMetaData) GetColumns(tableNames ...string) ([]dbi.Column, error) {
|
||||
DataType: dbi.ColumnDataType(anyx.ToString(re["DATA_TYPE"])),
|
||||
CharMaxLength: cast.ToInt(re["CHAR_MAX_LENGTH"]),
|
||||
ColumnComment: cast.ToString(re["COLUMN_COMMENT"]),
|
||||
Nullable: cast.ToString(re["NULLABLE"]),
|
||||
Nullable: cast.ToString(re["NULLABLE"]) == "YES",
|
||||
IsPrimaryKey: cast.ToInt(re["IS_PRIMARY_KEY"]) == 1,
|
||||
IsIdentity: cast.ToInt(re["IS_IDENTITY"]) == 1,
|
||||
ColumnDefault: cast.ToString(re["COLUMN_DEFAULT"]),
|
||||
@@ -182,7 +182,7 @@ func (dd *DMMetaData) genColumnBasicSql(column dbi.Column) string {
|
||||
}
|
||||
|
||||
nullAble := ""
|
||||
if column.Nullable == "NO" {
|
||||
if !column.Nullable {
|
||||
nullAble = " NOT NULL"
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ func (md *MssqlMetaData) GetColumns(tableNames ...string) ([]dbi.Column, error)
|
||||
DataType: dbi.ColumnDataType(anyx.ToString(re["DATA_TYPE"])),
|
||||
CharMaxLength: cast.ToInt(re["CHAR_MAX_LENGTH"]),
|
||||
ColumnComment: anyx.ToString(re["COLUMN_COMMENT"]),
|
||||
Nullable: anyx.ToString(re["NULLABLE"]),
|
||||
Nullable: anyx.ToString(re["NULLABLE"]) == "YES",
|
||||
IsPrimaryKey: cast.ToInt(re["IS_PRIMARY_KEY"]) == 1,
|
||||
IsIdentity: cast.ToInt(re["IS_IDENTITY"]) == 1,
|
||||
ColumnDefault: cast.ToString(re["COLUMN_DEFAULT"]),
|
||||
@@ -287,7 +287,7 @@ func (md *MssqlMetaData) genColumnBasicSql(column dbi.Column) string {
|
||||
}
|
||||
|
||||
nullAble := ""
|
||||
if column.Nullable == "NO" {
|
||||
if !column.Nullable {
|
||||
nullAble = " NOT NULL"
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ func (md *MysqlMetaData) GetColumns(tableNames ...string) ([]dbi.Column, error)
|
||||
ColumnName: cast.ToString(re["columnName"]),
|
||||
DataType: dbi.ColumnDataType(cast.ToString(re["dataType"])),
|
||||
ColumnComment: cast.ToString(re["columnComment"]),
|
||||
Nullable: cast.ToString(re["nullable"]),
|
||||
Nullable: cast.ToString(re["nullable"]) == "YES",
|
||||
IsPrimaryKey: cast.ToInt(re["isPrimaryKey"]) == 1,
|
||||
IsIdentity: cast.ToInt(re["isIdentity"]) == 1,
|
||||
ColumnDefault: cast.ToString(re["columnDefault"]),
|
||||
@@ -212,7 +212,7 @@ func (md *MysqlMetaData) genColumnBasicSql(column dbi.Column) string {
|
||||
}
|
||||
|
||||
nullAble := ""
|
||||
if column.Nullable == "NO" {
|
||||
if !column.Nullable {
|
||||
nullAble = " NOT NULL"
|
||||
}
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ func (od *OracleMetaData) GetColumns(tableNames ...string) ([]dbi.Column, error)
|
||||
ColumnName: cast.ToString(re["COLUMN_NAME"]),
|
||||
DataType: dbi.ColumnDataType(cast.ToString(re["DATA_TYPE"])),
|
||||
ColumnComment: cast.ToString(re["COLUMN_COMMENT"]),
|
||||
Nullable: cast.ToString(re["NULLABLE"]),
|
||||
Nullable: cast.ToString(re["NULLABLE"]) == "YES",
|
||||
IsPrimaryKey: cast.ToInt(re["IS_PRIMARY_KEY"]) == 1,
|
||||
IsIdentity: cast.ToInt(re["IS_IDENTITY"]) == 1,
|
||||
ColumnDefault: defaultVal,
|
||||
@@ -245,7 +245,7 @@ func (od *OracleMetaData) genColumnBasicSql(column dbi.Column) string {
|
||||
}
|
||||
|
||||
nullAble := ""
|
||||
if column.Nullable == "NO" {
|
||||
if !column.Nullable {
|
||||
nullAble = " NOT NULL"
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ func (pd *PgsqlMetaData) GetColumns(tableNames ...string) ([]dbi.Column, error)
|
||||
DataType: dbi.ColumnDataType(cast.ToString(re["dataType"])),
|
||||
CharMaxLength: cast.ToInt(re["charMaxLength"]),
|
||||
ColumnComment: cast.ToString(re["columnComment"]),
|
||||
Nullable: cast.ToString(re["nullable"]),
|
||||
Nullable: cast.ToString(re["nullable"]) == "YES",
|
||||
IsPrimaryKey: cast.ToInt(re["isPrimaryKey"]) == 1,
|
||||
IsIdentity: cast.ToInt(re["isIdentity"]) == 1,
|
||||
ColumnDefault: cast.ToString(re["columnDefault"]),
|
||||
@@ -238,7 +238,7 @@ func (pd *PgsqlMetaData) genColumnBasicSql(column dbi.Column) string {
|
||||
}
|
||||
|
||||
nullAble := ""
|
||||
if column.Nullable == "NO" {
|
||||
if !column.Nullable {
|
||||
nullAble = " NOT NULL"
|
||||
// 如果字段不能为空,则设置默认值
|
||||
if column.ColumnDefault == "" {
|
||||
|
||||
@@ -109,10 +109,6 @@ func (sd *SqliteMetaData) GetColumns(tableNames ...string) ([]dbi.Column, error)
|
||||
continue
|
||||
}
|
||||
for _, re := range res {
|
||||
nullable := "YES"
|
||||
if cast.ToInt(re["notnull"]) == 1 {
|
||||
nullable = "NO"
|
||||
}
|
||||
// 去掉默认值的引号
|
||||
defaultValue := cast.ToString(re["dflt_value"])
|
||||
if strings.Contains(defaultValue, "'") {
|
||||
@@ -123,7 +119,7 @@ func (sd *SqliteMetaData) GetColumns(tableNames ...string) ([]dbi.Column, error)
|
||||
TableName: tableName,
|
||||
ColumnName: cast.ToString(re["name"]),
|
||||
ColumnComment: "",
|
||||
Nullable: nullable,
|
||||
Nullable: cast.ToInt(re["notnull"]) != 1,
|
||||
IsPrimaryKey: cast.ToInt(re["pk"]) == 1,
|
||||
IsIdentity: cast.ToInt(re["pk"]) == 1,
|
||||
ColumnDefault: defaultValue,
|
||||
@@ -226,14 +222,13 @@ func (sd *SqliteMetaData) GenerateIndexDDL(indexs []dbi.Index, tableInfo dbi.Tab
|
||||
}
|
||||
|
||||
func (sd *SqliteMetaData) genColumnBasicSql(column dbi.Column) string {
|
||||
|
||||
incr := ""
|
||||
if column.IsIdentity {
|
||||
incr = " AUTOINCREMENT"
|
||||
}
|
||||
|
||||
nullAble := ""
|
||||
if column.Nullable == "NO" {
|
||||
if !column.Nullable {
|
||||
nullAble = " NOT NULL"
|
||||
}
|
||||
|
||||
@@ -281,7 +276,7 @@ func (sd *SqliteMetaData) GenerateTableDDL(columns []dbi.Column, tableInfo dbi.T
|
||||
fields = append(fields, sd.genColumnBasicSql(column))
|
||||
}
|
||||
createSql += strings.Join(fields, ",")
|
||||
createSql += fmt.Sprintf(") ")
|
||||
createSql += ") "
|
||||
|
||||
sqlArr = append(sqlArr, createSql)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user