mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-02 15:30:25 +08:00
fix:
1、pgsql驱动换成高斯db驱动 2、sql格式化支持传数据库类型
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import { h, render, VNode } from 'vue';
|
||||
import SqlExecDialog from './SqlExecDialog.vue';
|
||||
import {SqlLanguage} from 'sql-formatter/lib/src/sqlFormatter'
|
||||
|
||||
export type SqlExecProps = {
|
||||
sql: string;
|
||||
dbId: number;
|
||||
db: string;
|
||||
dbType?: SqlLanguage;
|
||||
runSuccessCallback?: Function;
|
||||
cancelCallback?: Function;
|
||||
};
|
||||
|
||||
@@ -113,7 +113,8 @@ const cancel = () => {
|
||||
const open = (props: SqlExecProps) => {
|
||||
runSuccessCallback = props.runSuccessCallback;
|
||||
cancelCallback = props.cancelCallback;
|
||||
state.sqlValue = sqlFormatter(props.sql);
|
||||
props.dbType = props.dbType || 'mysql';
|
||||
state.sqlValue = sqlFormatter(props.sql, { language: props.dbType });
|
||||
state.dbId = props.dbId;
|
||||
state.db = props.db;
|
||||
state.dialogVisible = true;
|
||||
|
||||
@@ -135,6 +135,7 @@ import { reactive, ref, toRefs, watch } from 'vue';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import SqlExecBox from '../sqleditor/SqlExecBox';
|
||||
import { getDbDialect, DbType } from '../../dialect/index';
|
||||
import { SqlLanguage } from 'sql-formatter/lib/src/sqlFormatter';
|
||||
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
@@ -421,10 +422,20 @@ const submit = async () => {
|
||||
ElMessage.warning('没有更改');
|
||||
return;
|
||||
}
|
||||
let dbType: SqlLanguage = '';
|
||||
switch (props.dbType) {
|
||||
case DbType.mysql:
|
||||
dbType = DbType.mysql;
|
||||
break;
|
||||
case DbType.postgresql:
|
||||
dbType = 'postgresql';
|
||||
break;
|
||||
}
|
||||
SqlExecBox({
|
||||
sql: sql,
|
||||
dbId: props.dbId as any,
|
||||
db: props.db as any,
|
||||
dbType,
|
||||
runSuccessCallback: () => {
|
||||
emit('submit-sql', { tableName: state.tableData.tableName });
|
||||
// cancel();
|
||||
|
||||
@@ -125,6 +125,10 @@ class PostgresqlDialect implements DbDialect {
|
||||
marks = true;
|
||||
}
|
||||
}
|
||||
// 哪些函数不需要加引号
|
||||
if (this.matchType(cl.value, ['nextval'])) {
|
||||
marks = false;
|
||||
}
|
||||
return ` DEFAULT ${marks ? "'" : ''}${cl.value}${marks ? "'" : ''}`;
|
||||
}
|
||||
return '';
|
||||
|
||||
@@ -3,6 +3,7 @@ module mayfly-go
|
||||
go 1.21
|
||||
|
||||
require (
|
||||
gitee.com/opengauss/openGauss-connector-go-pq v1.0.4
|
||||
github.com/buger/jsonparser v1.1.1
|
||||
github.com/gin-gonic/gin v1.9.1
|
||||
github.com/glebarez/sqlite v1.10.0
|
||||
@@ -15,7 +16,6 @@ require (
|
||||
github.com/golang-jwt/jwt/v5 v5.1.0
|
||||
github.com/gorilla/websocket v1.5.1
|
||||
github.com/kanzihuang/vitess/go/vt/sqlparser v0.0.0-20231018071450-ac8d9f0167e9
|
||||
github.com/lib/pq v1.10.9
|
||||
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20230712084735-068dc2aee82d
|
||||
github.com/mojocn/base64Captcha v1.3.5 // 验证码
|
||||
github.com/pkg/errors v0.9.1
|
||||
@@ -68,6 +68,7 @@ require (
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/tjfoc/gmsm v1.4.1 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
||||
@@ -81,6 +82,7 @@ require (
|
||||
golang.org/x/sync v0.1.0 // indirect
|
||||
golang.org/x/sys v0.14.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/genproto v0.0.0-20230131230820-1c016267d619 // indirect
|
||||
google.golang.org/grpc v1.52.3 // indirect
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
pq "gitee.com/opengauss/openGauss-connector-go-pq"
|
||||
"github.com/kanzihuang/vitess/go/vt/sqlparser"
|
||||
"github.com/lib/pq"
|
||||
)
|
||||
|
||||
type DbType string
|
||||
|
||||
@@ -12,11 +12,11 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/lib/pq"
|
||||
pq "gitee.com/opengauss/openGauss-connector-go-pq"
|
||||
)
|
||||
|
||||
func getPgsqlDB(d *DbInfo) (*sql.DB, error) {
|
||||
driverName := string(d.Type)
|
||||
driverName := "opengauss"
|
||||
// SSH Conect
|
||||
if d.SshTunnelMachineId > 0 {
|
||||
// 如果使用了隧道,则使用`postgres:ssh:隧道机器id`注册名
|
||||
@@ -41,7 +41,7 @@ func getPgsqlDB(d *DbInfo) (*sql.DB, error) {
|
||||
}
|
||||
}
|
||||
|
||||
dsn := fmt.Sprintf("host=%s port=%d user=%s password=%s %s sslmode=disable", d.Host, d.Port, d.Username, d.Password, dbParam)
|
||||
dsn := fmt.Sprintf("host=%s port=%d user=%s password='%s' %s sslmode=disable", d.Host, d.Port, d.Username, d.Password, dbParam)
|
||||
// 存在额外指定参数,则拼接该连接参数
|
||||
if d.Params != "" {
|
||||
// 存在指定的db,则需要将dbInstance配置中的parmas排除掉dbname和search_path
|
||||
|
||||
Reference in New Issue
Block a user