Skip to content

Commit

Permalink
🍰🍰🍰修复新建连接重复的tab计算问题
Browse files Browse the repository at this point in the history
修复打开软件界面布局错乱问题
😀优化新建连接默认当前数据连接配置
👀Windows安装目录重新设定为Gormat/版本号
📌readme排版
  • Loading branch information
airplayx committed Mar 17, 2020
1 parent c4281a5 commit bed0bb2
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 33 deletions.
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
- [x] Sql转Struct
- [x] Json转Struct

## About 说明

在golang开发中,有很多时候需要手动敲结构体,并且需要手动入库。尽管gorm有自动迁移的功能,但并不能有效、理想化的形成数据库字段。
网上也有很多开源的例子,但是都没有界面化并且方便管理的工具,所以我开始写这个项目,目的就是更高效的开发,转换即用。

本项目借鉴了许多开源转换库的代码,并结合orm进行适度调整。在开发中遇到了很多的问题,fyne这个GUI开发框架也是有很多坑点的,现不赘述。不管是数据库转Struct,还是Struct转SQL语句,普遍还存在一些误差,所以转换结果仅供参考,
实际项目请自行调整使用。

### Prerequisites 开发条件

```
Expand Down Expand Up @@ -98,17 +106,6 @@ go build -o gormat.exe -ldflags="-H windowsgui"
* 测试开源版本
* 0.0.1
* gormat lite

## About 关于

* **[airplayx](http://airplayx.com)**

在golang开发中,有很多时候需要手动敲结构体,并且需要手动入库。尽管gorm有自动迁移的功能,但并不能有效、理想化的形成数据库字段。
网上也有很多开源的例子,但是都没有界面化并且方便管理的工具,所以我开始写这个项目,目的就是更高效的开发,转换即用。

本项目借鉴了许多开源转换库的代码,并结合orm进行适度调整。在开发中遇到了很多的问题,fyne这个GUI开发框架也是有很多坑点的,现不赘述。不管是数据库转Struct,还是Struct转SQL语句,普遍还存在一些误差,所以转换结果仅供参考,
实际项目请自行调整使用。

## License 授权协议

这个项目 MIT 协议, 请点击 [LICENSE](LICENSE) 了解更多细节。
4 changes: 2 additions & 2 deletions cmd/build.iss
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName=D:\gormat_{#MyAppVersion}
DefaultGroupName=gormat
DefaultDirName=D:\Gormat\{#MyAppVersion}
DefaultGroupName=Gormat
DisableProgramGroupPage=yes
; 移除以下行,以在管理安装模式下运行(为所有用户安装)。
PrivilegesRequired=lowest
Expand Down
1 change: 1 addition & 0 deletions internal/app/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func Container(app fyne.App, win fyne.Window) *widget.TabContainer {
i = icon.Mssql
}
ipBox.Append(widget.NewTabItemWithIcon(v.Host+":"+v.Port, i, dbBox))
dbBox.SelectTabIndex(len(dbBox.Items) - 1)
}
if len(ipBox.Items) == 0 {
ipBox.Hide()
Expand Down
31 changes: 15 additions & 16 deletions internal/app/sql2struct/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ func DataBase(window, currentWindow fyne.Window, ipBox *widget.TabContainer, opt
port.SetText(currentLink.Port)
password.SetText(currentLink.Password)
user.SetText(currentLink.User)
db.SetText(currentLink.Db[dbIndex[1]])
if len(dbIndex) > 1 {
db.SetText(currentLink.Db[dbIndex[1]])
}
}
testDb := widget.NewHBox(widget.NewButton("测试连接", func() {
progressDialog := dialog.NewProgress("连接中", host.Text, currentWindow)
Expand Down Expand Up @@ -76,9 +78,6 @@ func DataBase(window, currentWindow fyne.Window, ipBox *widget.TabContainer, opt
currentWindow.Close()
},
OnSubmit: func() {
defer func() {
window.Canvas().Refresh(ipBox)
}()
newDB := widget.NewTabItemWithIcon(
db.Text, icon.Database,
Screen(currentWindow, &Sql2struct.SourceMap{
Expand All @@ -91,6 +90,10 @@ func DataBase(window, currentWindow fyne.Window, ipBox *widget.TabContainer, opt
}))
var dbBox = widget.NewTabContainer(newDB)
dbBox.SetTabLocation(widget.TabLocationLeading)
defer func() {
window.Canvas().Refresh(ipBox)
dbBox.SelectTab(newDB)
}()
i := icon.Mysql
switch strings.Title(driver.Selected) {
case "PostgreSQL":
Expand All @@ -101,7 +104,7 @@ func DataBase(window, currentWindow fyne.Window, ipBox *widget.TabContainer, opt
i = icon.Mssql
}
sourceMap := options.SourceMap
oldHost := false
oldIP := false
for _, v := range sourceMap {
if v.Host+":"+v.Port == host.Text+":"+port.Text {
for _, curDb := range v.Db {
Expand All @@ -110,12 +113,12 @@ func DataBase(window, currentWindow fyne.Window, ipBox *widget.TabContainer, opt
return
}
}
oldHost = true
oldIP = true
}
}
if oldHost {
if oldIP {
dbBox = ipBox.CurrentTab().Content.(*widget.TabContainer)
if dbIndex != nil {
if dbIndex != nil && len(dbIndex) > 1 {
currentLink := sourceMap[dbIndex[0]]
currentLink.Driver = driver.Selected
currentLink.Db[dbIndex[1]] = db.Text
Expand All @@ -128,15 +131,15 @@ func DataBase(window, currentWindow fyne.Window, ipBox *widget.TabContainer, opt
for k, v := range sourceMap {
if v.Host+":"+v.Port == host.Text+":"+port.Text {
ipBox.SelectTabIndex(k)
dbBox.Append(newDB)
ipBox.CurrentTab().Content.(*widget.TabContainer).Append(newDB)
sourceMap[k].Db = Sql2struct.RmDuplicateElement(append(v.Db, db.Text))
break
}
}
} else {
newDbBox := widget.NewTabContainer(newDB)
newDbBox.SetTabLocation(widget.TabLocationLeading)
ipBox.Append(widget.NewTabItemWithIcon(host.Text+":"+port.Text, i, newDbBox))
ipBox.Append(widget.NewTabItemWithIcon(host.Text+":"+port.Text, i, dbBox))
ipBox.SetTabLocation(widget.TabLocationLeading)
ipBox.SelectTabIndex(len(ipBox.Items) - 1)
options.SourceMap = append(sourceMap, Sql2struct.SourceMap{
Driver: driver.Selected,
Host: host.Text,
Expand All @@ -149,10 +152,6 @@ func DataBase(window, currentWindow fyne.Window, ipBox *widget.TabContainer, opt
jsons, _ := json.Marshal(options)
if data, err := jsonparser.Set(configs.Json, jsons, "sql2struct"); err == nil {
configs.Json = data
if dbIndex != nil {
ipBox.CurrentTab().Text = host.Text + ":" + port.Text
dbBox.CurrentTab().Text = db.Text
}
defer func() {
if ipBox.Hidden {
ipBox.Show()
Expand Down
19 changes: 15 additions & 4 deletions internal/app/toolbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,19 @@ import (
func ToolBar(win fyne.Window, ipBox *widget.TabContainer, options *Sql2struct.SQL2Struct) *widget.Toolbar {
return widget.NewToolbar(
widget.NewToolbarAction(icon.Insert, func() {
var dbIndex []int
if ipBox.Items != nil && ipBox.Visible() {
sourceMap := options.SourceMap
for k, v := range sourceMap {
if v.Host+":"+v.Port == ipBox.CurrentTab().Text {
dbIndex = []int{k}
break
}
}
}
w := fyne.CurrentApp().NewWindow("添加连接")
w.SetContent(widget.NewScrollContainer(
sql2struct.DataBase(win, w, ipBox, options, nil)),
sql2struct.DataBase(win, w, ipBox, options, dbIndex)),
)
w.Resize(fyne.Size{Width: 650, Height: 300})
w.CenterOnScreen()
Expand Down Expand Up @@ -98,13 +108,14 @@ func ToolBar(win fyne.Window, ipBox *widget.TabContainer, options *Sql2struct.SQ
return
}
dbBox := ipBox.CurrentTab().Content.(*widget.TabContainer)
win.Canvas().Refresh(dbBox)
w := fyne.CurrentApp().NewWindow("编辑连接")
sourceMap := options.SourceMap
var dbIndex []int
for k, v := range sourceMap {
if v.Host+":"+v.Port == ipBox.CurrentTab().Text {
for key, db := range v.Db {
if db == dbBox.CurrentTab().Text {
for key := range v.Db {
if key == dbBox.CurrentTabIndex() {
dbIndex = []int{k, key}
goto loop
}
Expand Down Expand Up @@ -172,9 +183,9 @@ func ToolBar(win fyne.Window, ipBox *widget.TabContainer, options *Sql2struct.SQ
if len(sourceMap[k].Db) == 0 {
options.SourceMap = append(sourceMap[:k], sourceMap[k+1:]...)
}

if dbBox.CurrentTabIndex() >= 0 && dbBox.CurrentTabIndex() < len(dbBox.Items)-1 {
dbBox.RemoveIndex(dbBox.CurrentTabIndex())
dbBox.SelectTabIndex(dbBox.CurrentTabIndex())
goto loop
} else if dbBox.CurrentTabIndex() > 0 && dbBox.CurrentTabIndex() == len(dbBox.Items)-1 {
dbBox.SelectTabIndex(dbBox.CurrentTabIndex() - 1)
Expand Down

0 comments on commit bed0bb2

Please sign in to comment.