mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-02 15:30:25 +08:00
feat: 数据库支持选中数据生成insert语句
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
"countup.js": "^2.0.7",
|
||||
"cropperjs": "^1.5.11",
|
||||
"echarts": "^5.3.3",
|
||||
"element-plus": "^2.2.10",
|
||||
"element-plus": "2.2.9",
|
||||
"jsencrypt": "^3.2.1",
|
||||
"jsoneditor": "^9.9.0",
|
||||
"lodash": "^4.17.21",
|
||||
|
||||
@@ -152,6 +152,10 @@
|
||||
<el-tooltip class="box-item" effect="dark" content="commit" placement="top">
|
||||
<el-link @click="onCommit" class="ml5" type="success" icon="check" :underline="false"></el-link>
|
||||
</el-tooltip>
|
||||
|
||||
<el-tooltip class="box-item" effect="dark" content="生成insert sql" placement="top">
|
||||
<el-link @click="onGenerateInsertSql" type="success" class="ml20" :underline="false">gi</el-link>
|
||||
</el-tooltip>
|
||||
</el-row>
|
||||
<el-row class="mt5">
|
||||
<el-input
|
||||
@@ -263,6 +267,10 @@
|
||||
</span>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog @close="genSqlDialog.visible = false" v-model="genSqlDialog.visible" title="SQL" width="1000px">
|
||||
<el-input v-model="genSqlDialog.sql" type="textarea" rows="20" />
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -353,6 +361,10 @@ export default defineComponent({
|
||||
condition: '=',
|
||||
value: null,
|
||||
},
|
||||
genSqlDialog: {
|
||||
visible: false,
|
||||
sql: '',
|
||||
},
|
||||
cmOptions: {
|
||||
tabSize: 4,
|
||||
mode: 'text/x-sql',
|
||||
@@ -1016,6 +1028,38 @@ export default defineComponent({
|
||||
});
|
||||
};
|
||||
|
||||
const onGenerateInsertSql = async () => {
|
||||
const queryTab = isQueryTab();
|
||||
const datas = queryTab ? state.queryTab.selectionDatas : state.dataTabs[state.activeName].selectionDatas;
|
||||
isTrue(datas && datas.length > 0, '请先选择要生成insert语句的数据');
|
||||
const tableName = state.nowTableName;
|
||||
const columns: any = await getColumns(tableName);
|
||||
|
||||
const sqls = [];
|
||||
for (let data of datas) {
|
||||
let colNames = [];
|
||||
let values = [];
|
||||
for (let column of columns) {
|
||||
const colName = column.columnName;
|
||||
colNames.push(colName);
|
||||
values.push(wrapValueByType(data[colName]));
|
||||
}
|
||||
sqls.push(`INSERT INTO ${tableName} (${colNames.join(', ')}) VALUES(${values.join(', ')})`);
|
||||
}
|
||||
state.genSqlDialog.sql = sqls.join(';\n') + ';';
|
||||
state.genSqlDialog.visible = true;
|
||||
};
|
||||
|
||||
const wrapValueByType = (val: any) => {
|
||||
if (val == null) {
|
||||
return 'NULL';
|
||||
}
|
||||
if (typeof val == 'number') {
|
||||
return val;
|
||||
}
|
||||
return `'${val}'`;
|
||||
};
|
||||
|
||||
/**
|
||||
* 是否为查询tab
|
||||
*/
|
||||
@@ -1192,6 +1236,7 @@ export default defineComponent({
|
||||
onDataSelectionChange,
|
||||
onDeleteData,
|
||||
onTableSortChange,
|
||||
onGenerateInsertSql,
|
||||
showExecBtns,
|
||||
closeExecBtns,
|
||||
};
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
</el-row>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog :title="tree.title" v-model="tree.visible" :close-on-click-modal="false" width="680px">
|
||||
<el-dialog :title="tree.title" v-model="tree.visible" :close-on-click-modal="false" width="50%">
|
||||
<el-progress
|
||||
v-if="uploadProgressShow"
|
||||
style="width: 90%; margin-left: 20px"
|
||||
|
||||
@@ -633,10 +633,10 @@ echarts@^5.3.3:
|
||||
tslib "2.3.0"
|
||||
zrender "5.3.2"
|
||||
|
||||
element-plus@^2.2.10:
|
||||
version "2.2.10"
|
||||
resolved "https://registry.npmmirror.com/element-plus/-/element-plus-2.2.10.tgz#0b06a006b67b7ad3d5f071545a910782f9ba471b"
|
||||
integrity sha512-hJ+LlbRN3POu4Idl1LXB+SHSWdi+wwmdsoDXdQT2ynGuwzZsMYiusOooYXyEsPlrizeLibdnNGNDx4TIjXQvUg==
|
||||
element-plus@2.2.9:
|
||||
version "2.2.9"
|
||||
resolved "https://registry.npmmirror.com/element-plus/-/element-plus-2.2.9.tgz#f0366dfb2048d614813926274cb443f17e5fdef2"
|
||||
integrity sha512-jYbL0JkCdv95rkT6trZJjCAizLPySa0qcd2cgq+57SKQnCZAcNDDq4GbTuFRnNavdoeCJnuM3HIficTIUpsMOQ==
|
||||
dependencies:
|
||||
"@ctrl/tinycolor" "^3.4.1"
|
||||
"@element-plus/icons-vue" "^2.0.6"
|
||||
|
||||
@@ -25,7 +25,8 @@ server:
|
||||
filepath: ./static/config.js
|
||||
|
||||
jwt:
|
||||
key: mykey
|
||||
# jwt key,不设置默认使用随机字符串
|
||||
key:
|
||||
# 过期时间单位分钟
|
||||
expire-time: 1440
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ func NewLogicSshWsSession(cols, rows int, cli *Cli, wsConn *websocket.Conn) (*Lo
|
||||
ssh.TTY_OP_OSPEED: 14400, // output speed = 14.4kbaud
|
||||
}
|
||||
// Request pseudo terminal
|
||||
if err := sshSession.RequestPty("xterm", rows, cols, modes); err != nil {
|
||||
if err := sshSession.RequestPty("xterm-256color", rows, cols, modes); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Start remote shell
|
||||
|
||||
@@ -8,6 +8,5 @@ type Jwt struct {
|
||||
}
|
||||
|
||||
func (j *Jwt) Valid() {
|
||||
assert.IsTrue(j.Key != "", "config.yml之 [jwt.key] 不能为空")
|
||||
assert.IsTrue(j.ExpireTime != 0, "config.yml之 [jwt.expire-time] 不能为空")
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@ import (
|
||||
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/config"
|
||||
"mayfly-go/pkg/global"
|
||||
"mayfly-go/pkg/model"
|
||||
"mayfly-go/pkg/utils"
|
||||
"time"
|
||||
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
@@ -25,7 +27,11 @@ func CreateToken(userId uint64, username string) string {
|
||||
"username": username,
|
||||
"exp": time.Now().Add(time.Minute * time.Duration(ExpTime)).Unix(),
|
||||
})
|
||||
|
||||
// 如果jwt key为空,则随机生成字符串
|
||||
if JwtKey == "" {
|
||||
JwtKey = utils.RandString(32)
|
||||
global.Log.Infof("config.yml未配置jwt.key, 随机生成key为: %s", JwtKey)
|
||||
}
|
||||
// 使用自定义字符串加密 and get the complete encoded token as a string
|
||||
tokenString, err := token.SignedString([]byte(JwtKey))
|
||||
biz.ErrIsNil(err, "token创建失败")
|
||||
|
||||
25
server/pkg/utils/rand.go
Normal file
25
server/pkg/utils/rand.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
const randChar = "0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
|
||||
// 生成随机字符串
|
||||
func RandString(l int) string {
|
||||
strList := []byte(randChar)
|
||||
|
||||
result := []byte{}
|
||||
i := 0
|
||||
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
charLen := len(strList)
|
||||
for i < l {
|
||||
new := strList[r.Intn(charLen)]
|
||||
result = append(result, new)
|
||||
i = i + 1
|
||||
}
|
||||
return string(result)
|
||||
}
|
||||
Reference in New Issue
Block a user