Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
pull
Browse files Browse the repository at this point in the history
  • Loading branch information
shanhexi committed May 17, 2023
2 parents f1cf717 + 0daca93 commit 190ae4b
Show file tree
Hide file tree
Showing 140 changed files with 4,995 additions and 3,099 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@

### docker 数据不用上传
/docker/redis/data/*
/ali-dbhub-server/ali-dbhub-server-domain/ali-dbhub-server-domain-support/src/main/resources/lib/*
/ali-dbhub-server/ali-dbhub-server-domain/ali-dbhub-server-domain-support/lib/*
/lib
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 1.0.3
* 🔥 支持SSH连接数据库
* 🎉 支持客户端查看日志
* 🎉 支持在Console中聊天对话
* 支持在客户端内设置OPENAI代理 [Issue #84](https://github.com/alibaba/Chat2DB/issues/84)
* 已经启动过应用不会再重复启动 [Issue #96](https://github.com/alibaba/Chat2DB/issues/96)

# 1.0.1
* 修复oracle连接配置编辑、以及连接查询问题
* 修复Apikey输出到日志可能存在的风险
* 修复web版本登录的bug

# 1.0.0
Chat2DB的 1.0.0 正式版来啦🎉🎉🎉🎉🎉🎉🎉🎉🎉

* 🌈 AI智能助手,支持自然语言转SQL、SQL转自然语言、SQL优化建议
* 👭 支持团队协作,研发无需知道线上数据库密码,解决企业数据库账号安全问题
* ⚙️ 强大的数据管理能力,支持数据表、视图、存储过程、函数、触发器、索引、序列、用户、角色、授权等管理
* 🔌 强大的扩展能力,目前已经支持Mysql、PostgreSQL、Oracle、SQLServer、ClickHouse、Oceanbase、H2、SQLite等等,未来会支持更多的数据库
* 🛡 前端使用 Electron 开发,提供 Windows、Mac、Linux 客户端、网页版本一体化的解决方案
* 🎁 支持环境隔离、线上、日常数据权限分离
34 changes: 33 additions & 1 deletion CHAT2DB_AI_SQL.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Chat2DB包含一系列基于ChatGPT的AI SQL使用功能,主要包括自然语
### 点击设置
<a><img src="https://img.alicdn.com/imgextra/i2/O1CN01hecdtO1acLegtiP9k_!!6000000003350-2-tps-2400-1600.png" width="100%"/></a>
### 配置OPENAI_API_KEY
<a><img src="https://img.alicdn.com/imgextra/i4/O1CN0197wmQv1XFV33cm1aY_!!6000000002894-2-tps-1054-590.png" width="100%"/></a>
使用ChatSql功能之前必须配置OPENAI_API_KEY,也可在客户端中设置代理HOST和PORT
<a><img src="https://img.alicdn.com/imgextra/i2/O1CN01mkVmEd1FTY7SBG6Lq_!!6000000000488-0-tps-1212-788.jpg" width="100%"/></a>

## 自然语言转SQL
### 功能描述
Expand Down Expand Up @@ -37,3 +38,34 @@ WHERE student.name = '小明'
输入SQL,选中执行并传入目标SQL类型和附加信息,附加信息中可以添加转换的自定义要求,则会返回目标SQL类型且符合附加要求的SQL语言
- 输入样例:SELECT IFNULL(NULL, "W3Schools.com"),目标SQL类型为Oracle SQL
- 输出样例:SELECT NVL(NULL, 'W3Schools.com') FROM dual;
## CHATBOT
### 功能描述
输入任意prompt,点击ChatRobot按钮即可根据prompt返回相应的结果,此处聊天对话默认支持上下文,默认上下文长度为4,可在application.yml文件中修改上下文长度
- 输入样例:针对第二条优化建议给出具体实现方法
- 输出样例:针对第二条优化建议,可以考虑在student表中添加一个索引,以加快查询速度。具体实现方法如下:

1. 查看student表中是否已经存在索引。可以使用以下命令查看:

```sql
SHOW INDEX FROM student;
```

如果已经存在索引,则可以跳过下一步。

2. 在student表中添加索引。可以使用以下命令添加:

```sql
ALTER TABLE student ADD INDEX name_index (name);
```

这里的name_index是索引的名称,name是需要建立索引的列名。

注意:如果student表中的数据量很大,添加索引可能需要一些时间。

3. 重新执行原始SQL语句,查看查询速度是否有所提升。

```sql
SELECT score.score FROM score INNER JOIN student ON score.student_id = student.id WHERE student.name = '小明';
```

如果查询速度有所提升,则说明索引建立成功。
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
## ⏬ 下载安装
| 描述 | 下载地址 |
|-----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Windows | [https://oss-chat2db.alibaba.com/release/1.0.1/Chat2DB%20Setup%201.0.1.exe](https://oss-chat2db.alibaba.com/release/1.0.1/Chat2DB%20Setup%201.0.1.exe) |
| MacOS ARM64 (Apple芯片) | [https://oss-chat2db.alibaba.com/release/1.0.1/Chat2DB-1.0.1-arm64.dmg](https://oss-chat2db.alibaba.com/release/1.0.1/Chat2DB-1.0.1-arm64.dmg) |
| MacOS X64 (Intel芯片) | [https://oss-chat2db.alibaba.com/release/1.0.1/Chat2DB-1.0.1.dmg](https://oss-chat2db.alibaba.com/release/1.0.1/Chat2DB-1.0.1.dmg) |
| Jar包 | [https://oss-chat2db.alibaba.com/release/1.0.1/ali-dbhub-server-start.jar](https://oss-chat2db.alibaba.com/release/1.0.1/ali-dbhub-server-start.jar) |
| Windows | [https://oss-chat2db.alibaba.com/release/1.0.3/Chat2DB%20Setup%201.0.3.exe](https://oss-chat2db.alibaba.com/release/1.0.3/Chat2DB%20Setup%201.0.3.exe) |
| MacOS ARM64 (Apple芯片) | [https://oss-chat2db.alibaba.com/release/1.0.3/Chat2DB-1.0.3-arm64.dmg](https://oss-chat2db.alibaba.com/release/1.0.3/Chat2DB-1.0.3-arm64.dmg) |
| MacOS X64 (Intel芯片) | [https://oss-chat2db.alibaba.com/release/1.0.3/Chat2DB-1.0.3.dmg](https://oss-chat2db.alibaba.com/release/1.0.3/Chat2DB-1.0.3.dmg) |
| Jar包 | [https://oss-chat2db.alibaba.com/release/1.0.3/ali-dbhub-server-start.jar](https://oss-chat2db.alibaba.com/release/1.0.3/ali-dbhub-server-start.jar) |

## 🌰 使用Demo
- 创建数据源
Expand Down
2 changes: 1 addition & 1 deletion ali-dbhub-client/.umirc.prod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineConfig } from 'umi';
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
const UMI_PublicPath = process.env.UMI_PublicPath || '/';
const UMI_PublicPath = process.env.UMI_PublicPath || '/static/front/';

const chainWebpack = (config: any, { webpack }: any) => {
config.plugin('monaco-editor').use(MonacoWebpackPlugin, [
Expand Down
128 changes: 119 additions & 9 deletions ali-dbhub-client/electron/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
// 引入electron并创建一个Browserwindow
const { app, BrowserWindow, shell, net } = require('electron');
const {
app,
BrowserWindow,
Menu,
shell,
net,
ipcMain,
dialog,
} = require('electron');
const path = require('path');
const url = require('url');
// const isDev = require('electron-is-dev');
// const { autoUpdater } = require('electron-updater');
const os = require('os');
const fs = require('fs');
const isPro = process.env.NODE_ENV !== 'development';
// 修改main.js实时更新
// reloader(module);
Expand All @@ -14,7 +21,8 @@ let mainWindow;
function createWindow() {
//创建浏览器窗口,宽高自定义具体大小你开心就好
let options = {};
if (process.platform === 'win32') { // 如果平台是win32,也即windows
if (process.platform === 'win32') {
// 如果平台是win32,也即windows
options.show = true; // 当window创建的时候打开
options.backgroundColor = '#3f3c37';
}
Expand All @@ -35,7 +43,7 @@ function createWindow() {
preload: path.join(__dirname, 'preload.js'),
},
});

// 加载应用----- electron-quick-start中默认的加载入口
mainWindow.loadFile(`${__dirname}/dist/index.html`);

Expand All @@ -62,7 +70,6 @@ process.on('uncaughtException', (error) => {
// 当 Electron 完成初始化并准备创建浏览器窗口时调用此方法
app.on('ready', createWindow);


app.on('before-quit', (event) => {
const request = net.request({
headers: {
Expand All @@ -85,7 +92,7 @@ app.on('before-quit', (event) => {
app.on('window-all-closed', function (event) {
// macOS中除非用户按下 `Cmd + Q` 显式退出,否则应用与菜单栏始终处于活动状态.
event.preventDefault();
app.hide()
app.hide();
// if (process.platform !== 'darwin') {
// app.quit();
// }
Expand All @@ -98,4 +105,107 @@ app.on('activate', function () {
}
});

// 你可以在这个脚本中续写或者使用require引入独立的js文件.
ipcMain.handle('get-product-name', (event) => {
const exePath = app.getPath('exe');
const { name } = path.parse(exePath);
return name;
});

// -------------------- 菜单栏 --------------------
const menuBar = [
{
label: '文件',
submenu: [
{
label: '关于Chat2DB',
click() {
dialog.showMessageBox({
title: '关于Chat2DB',
// message: '关于Chat2DB v1.0.0',
detail:
'一款由阿里巴巴开源免费的多数据库客户端工具,支持windows、mac本地安装,也支持服务器端部署,web网页访问。',
icon: './logo/icon.png',
});
},
},
{
label: '刷新',
accelerator: process.platform === 'darwin' ? 'Cmd+R' : 'Ctrl+R',
click() {
const focusedWindow = BrowserWindow.getFocusedWindow();
if (focusedWindow) {
focusedWindow.reload();
}
},
},
{
label: '退出',
accelerator: process.platform === 'darwin' ? 'Cmd+Q' : 'Alt+F4',
click() {
// 退出程序
app.quit();
},
},
],
},
{
label: '编辑',
submenu: [
{ label: '撤销', role: 'undo' },
{ label: '重做', role: 'redo' },
{ type: 'separator' },
{ label: '剪切', role: 'cut' },
{ label: '复制', role: 'copy' },
{ label: '粘贴', role: 'paste' },
{ label: '全选', role: 'selectAll' },
],
},
{
label: '帮助',
submenu: [
{
label: '打开日志',
accelerator:
process.platform === 'darwin' ? 'Cmd+Shift+L' : 'Ctrl+Shift+L',
click() {
const fileName = '.chat2db/logs/application.log';
const url = path.join(os.homedir(), fileName);
shell.openPath(url).then((str) => console.log('err:', str));
},
},
{
label: '打开控制台',
accelerator:
process.platform === 'darwin' ? 'Cmd+Shift+I' : 'Ctrl+Shift+I',
click() {
mainWindow && mainWindow.toggleDevTools();
},
},
{
label: '访问官网',
click() {
const url = 'https://chat2db.opensource.alibaba.com/';
shell.openExternal(url);
},
},
// {
// label: '关于',
// role: 'about', // about (关于),此值只针对 Mac OS X 系统
// // 点击事件 role 属性能识别时 点击事件无效
// click: () => {
// var aboutWin = new BrowserWindow({
// width: 300,
// height: 200,
// parent: win,
// modal: true,
// });
// aboutWin.loadFile('about.html');
// },
// },
],
},
];
// 构建菜单项
const menu = Menu.buildFromTemplate(menuBar);
// 设置一个顶部菜单栏
Menu.setApplicationMenu(menu);
3 changes: 1 addition & 2 deletions ali-dbhub-client/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@
{
"target": "nsis",
"arch": [
"x64",
"ia32"
"x64"
]
}
],
Expand Down
22 changes: 16 additions & 6 deletions ali-dbhub-client/electron/preload.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
const { contextBridge } = require('electron');
const { contextBridge, ipcRenderer } = require('electron');
const { spawn, exec } = require('child_process');
const path = require('path');
const {app} = require('electron');

const { app } = require('electron');

const appName = 'ali-dbhub-server-start.jar';
contextBridge.exposeInMainWorld('myAPI', {
startServerForSpawn: () => {
startServerForSpawn: async () => {
const path1 = path.join(__dirname, `app/${appName}`);
console.log('path1', path1);
const ls = spawn(path.join(__dirname, 'jre/bin/java') , ['-jar', '-Xmx128M', '-Dspring.profiles.active=release','-Dserver.address=127.0.0.1', path1]);

const productName = await ipcRenderer.invoke('get-product-name');
const isTest = productName.match(/test$/i) !== null;

console.log('productName:', productName, isTest);

const ls = spawn(path.join(__dirname, 'jre/bin/java'), [
'-jar',
'-Xmx512M',
`-Dspring.profiles.active=${isTest?'test':'release'}`,
'-Dserver.address=127.0.0.1',
path1,
]);
ls.stdout.on('data', (buffer) => {
console.log(buffer.toString('utf8'));
const data = buffer.toString('utf8');
Expand Down
2 changes: 1 addition & 1 deletion ali-dbhub-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"test": "umi-test",
"test:coverage": "umi-test --coverage",
"electron": "electron .",
"build:prod": "mkdir -p ../ali-dbhub-server/ali-dbhub-server-start/src/main/resources/static && rm -rf ../ali-dbhub-server/ali-dbhub-server-start/src/main/resources/static/front && cross-env UMI_ENV=prod cross-env UMI_PublicPath=${npm_config_publicPath} umi build && mv dist ../ali-dbhub-server/ali-dbhub-server-start/src/main/resources/static/front",
"build:prod": "mkdir -p ../ali-dbhub-server/ali-dbhub-server-start/src/main/resources/static && rm -rf ../ali-dbhub-server/ali-dbhub-server-start/src/main/resources/static/front && cross-env UMI_ENV=prod cross-env UMI_PublicPath=${npm_config_publicPath} umi build && mv dist ../ali-dbhub-server/ali-dbhub-server-start/src/main/resources/static/front",
"build:desktop": "cross-env UMI_ENV=desktop umi build"
},
"gitHooks": {
Expand Down
Binary file modified ali-dbhub-client/src/assets/chatLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ali-dbhub-client/src/assets/chatLogo.webp
Binary file not shown.
Binary file added ali-dbhub-client/src/assets/error.webp
Binary file not shown.
22 changes: 19 additions & 3 deletions ali-dbhub-client/src/assets/font/iconfont.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@font-face {
font-family: "iconfont"; /* Project id 3633546 */
src: url('iconfont.woff2?t=1682599433280') format('woff2'),
url('iconfont.woff?t=1682599433280') format('woff'),
url('iconfont.ttf?t=1682599433280') format('truetype');
src: url('iconfont.woff2?t=1683627839021') format('woff2'),
url('iconfont.woff?t=1683627839021') format('woff'),
url('iconfont.ttf?t=1683627839021') format('truetype');
}

.iconfont {
Expand All @@ -13,6 +13,22 @@
-moz-osx-font-smoothing: grayscale;
}

.icon-proxy:before {
content: "\e63f";
}

.icon-openai:before {
content: "\e646";
}

.icon-guanyu:before {
content: "\e60c";
}

.icon-yifu:before {
content: "\e666";
}

.icon-shujuku4:before {
content: "\e609";
}
Expand Down
Binary file modified ali-dbhub-client/src/assets/font/iconfont.ttf
Binary file not shown.
Binary file modified ali-dbhub-client/src/assets/font/iconfont.woff
Binary file not shown.
Binary file modified ali-dbhub-client/src/assets/font/iconfont.woff2
Binary file not shown.
Binary file added ali-dbhub-client/src/assets/ghost.webp
Binary file not shown.
Binary file added ali-dbhub-client/src/assets/h2-logo.webp
Binary file not shown.
Binary file added ali-dbhub-client/src/assets/moreDB-logo.webp
Binary file not shown.
Binary file added ali-dbhub-client/src/assets/mysql-logo.webp
Binary file not shown.
Binary file added ali-dbhub-client/src/assets/no-data.webp
Binary file not shown.
Binary file added ali-dbhub-client/src/assets/redis-logo.webp
Binary file not shown.
Binary file added ali-dbhub-client/src/assets/theme-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ali-dbhub-client/src/assets/theme-dark.webp
Binary file not shown.
Binary file added ali-dbhub-client/src/assets/theme-default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ali-dbhub-client/src/assets/theme-default.webp
Binary file not shown.
2 changes: 2 additions & 0 deletions ali-dbhub-client/src/components/BrandLogo/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
.box {
display: flex;
justify-content: center;
border-radius: 10%;
overflow: hidden;
img {
display: block;
height: 100%;
Expand Down
2 changes: 1 addition & 1 deletion ali-dbhub-client/src/components/BrandLogo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { memo } from 'react';
import styles from './index.less';
import classnames from 'classnames';
import logo from '@/assets/chatLogo.png'
import logo from '@/assets/chatLogo.webp';

interface IProps extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
className?: any;
Expand Down
Loading

0 comments on commit 190ae4b

Please sign in to comment.