Skip to content

Commit

Permalink
🚀 release 0.0.1
Browse files Browse the repository at this point in the history
修复新建连接不会呈现到窗口问题
修复添加/编辑数据库重复问题
  • Loading branch information
airplayx committed Mar 16, 2020
1 parent 14cfb8c commit c4281a5
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 59 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
- [x] 数据库转Struct
- [x] 数据引擎支持
- [x] Mysql
- [ ] PostgreSQL
- [ ] Sqlite3
- [ ] Mssql
- [x] 自动存文件
- [x] 标签支持
- [x] Gorm
Expand Down
6 changes: 3 additions & 3 deletions cmd/build.iss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档!

#define MyAppName "Gormat - Tool For Gopher"
#define MyAppVersion "beta"
#define MyAppVersion "0.0.1"
#define MyAppPublisher "airplayx"
#define MyAppURL "http://airplayx.com/"
#define MyAppExeName "gormat.exe"
Expand All @@ -19,14 +19,14 @@ AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName=D:\gormat_beta
DefaultDirName=D:\gormat_{#MyAppVersion}
DefaultGroupName=gormat
DisableProgramGroupPage=yes
; 移除以下行,以在管理安装模式下运行(为所有用户安装)。
PrivilegesRequired=lowest
PrivilegesRequiredOverridesAllowed=commandline
OutputDir=C:\Users\Administrator\Desktop
OutputBaseFilename=gormat_beta
OutputBaseFilename=gormat_{#MyAppVersion}
Compression=lzma
SolidCompression=yes
WizardStyle=modern
Expand Down
83 changes: 42 additions & 41 deletions internal/app/sql2struct/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"time"
)

func DataBase(win fyne.Window, ipBox *widget.TabContainer, options *Sql2struct.SQL2Struct, dbIndex []int) fyne.Widget {
func DataBase(window, currentWindow fyne.Window, ipBox *widget.TabContainer, options *Sql2struct.SQL2Struct, dbIndex []int) fyne.Widget {
driver := widget.NewSelect([]string{"Mysql" /*, "PostgreSQL", "Sqlite3", "Mssql"*/}, func(s string) {

})
Expand All @@ -44,7 +44,7 @@ func DataBase(win fyne.Window, ipBox *widget.TabContainer, options *Sql2struct.S
db.SetText(currentLink.Db[dbIndex[1]])
}
testDb := widget.NewHBox(widget.NewButton("测试连接", func() {
progressDialog := dialog.NewProgress("连接中", host.Text, win)
progressDialog := dialog.NewProgress("连接中", host.Text, currentWindow)
go func() {
num := 0.0
for num < 1.0 {
Expand All @@ -65,20 +65,23 @@ func DataBase(win fyne.Window, ipBox *widget.TabContainer, options *Sql2struct.S
Driver: driver.Selected,
})
if err != nil {
dialog.ShowError(errors.New(err.Error()), win)
dialog.ShowError(errors.New(err.Error()), currentWindow)
} else {
dialog.ShowInformation("成功", "连接成功", win)
dialog.ShowInformation("成功", "连接成功", currentWindow)
_ = Sql2struct.DB().Close()
}
}))
return &widget.Form{
OnCancel: func() {
win.Close()
currentWindow.Close()
},
OnSubmit: func() {
defer func() {
window.Canvas().Refresh(ipBox)
}()
newDB := widget.NewTabItemWithIcon(
db.Text, icon.Database,
Screen(win, &Sql2struct.SourceMap{
Screen(currentWindow, &Sql2struct.SourceMap{
Driver: driver.Selected,
Host: host.Text,
User: user.Text,
Expand All @@ -97,52 +100,51 @@ func DataBase(win fyne.Window, ipBox *widget.TabContainer, options *Sql2struct.S
case "Mssql":
i = icon.Mssql
}

sourceMap := options.SourceMap
oldHost := false
for _, v := range sourceMap {
if v.Host+":"+v.Port == host.Text+":"+port.Text {
for _, curDb := range v.Db {
if curDb == db.Text && v.Password == password.Text {
dialog.ShowError(errors.New("已存在相同的连接"), win)
dialog.ShowError(errors.New("已存在相同的连接"), currentWindow)
return
}
}
oldHost = true
}
}
if dbIndex != nil {
currentLink := sourceMap[dbIndex[0]]
currentLink.Driver = driver.Selected
currentLink.Db[dbIndex[1]] = db.Text
currentLink.User = user.Text
currentLink.Password = password.Text
currentLink.Host = host.Text
currentLink.Port = port.Text
} else {
if oldHost {
dbBox = ipBox.CurrentTab().Content.(*widget.TabContainer)
for k, v := range sourceMap {
if v.Host+":"+v.Port == host.Text+":"+port.Text {
ipBox.SelectTabIndex(k)
dbBox.Append(newDB)
sourceMap[k].Db = append(v.Db, db.Text)
}
if oldHost {
dbBox = ipBox.CurrentTab().Content.(*widget.TabContainer)
if dbIndex != nil {
currentLink := sourceMap[dbIndex[0]]
currentLink.Driver = driver.Selected
currentLink.Db[dbIndex[1]] = db.Text
currentLink.User = user.Text
currentLink.Password = password.Text
currentLink.Host = host.Text
currentLink.Port = port.Text
dbBox.RemoveIndex(dbBox.CurrentTabIndex())
}
for k, v := range sourceMap {
if v.Host+":"+v.Port == host.Text+":"+port.Text {
ipBox.SelectTabIndex(k)
dbBox.Append(newDB)
sourceMap[k].Db = Sql2struct.RmDuplicateElement(append(v.Db, db.Text))
}
} else {
newDbBox := widget.NewTabContainer(newDB)
newDbBox.SetTabLocation(widget.TabLocationLeading)
ipBox.Append(widget.NewTabItemWithIcon(host.Text+":"+port.Text, i, newDbBox))
ipBox.SetTabLocation(widget.TabLocationLeading)
options.SourceMap = append(sourceMap, Sql2struct.SourceMap{
Driver: driver.Selected,
Host: host.Text,
User: user.Text,
Password: password.Text,
Port: port.Text,
Db: []string{db.Text},
})
}
} else {
newDbBox := widget.NewTabContainer(newDB)
newDbBox.SetTabLocation(widget.TabLocationLeading)
ipBox.Append(widget.NewTabItemWithIcon(host.Text+":"+port.Text, i, newDbBox))
ipBox.SetTabLocation(widget.TabLocationLeading)
options.SourceMap = append(sourceMap, Sql2struct.SourceMap{
Driver: driver.Selected,
Host: host.Text,
User: user.Text,
Password: password.Text,
Port: port.Text,
Db: []string{db.Text},
})
}
jsons, _ := json.Marshal(options)
if data, err := jsonparser.Set(configs.Json, jsons, "sql2struct"); err == nil {
Expand All @@ -155,11 +157,10 @@ func DataBase(win fyne.Window, ipBox *widget.TabContainer, options *Sql2struct.S
if ipBox.Hidden {
ipBox.Show()
}
ipBox.Refresh()
win.Close()
currentWindow.Close()
}()
} else {
dialog.ShowError(errors.New(err.Error()), win)
dialog.ShowError(errors.New(err.Error()), currentWindow)
}
},
Items: []*widget.FormItem{
Expand Down
2 changes: 1 addition & 1 deletion internal/app/sql2struct/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func Screen(win fyne.Window, dbConf *Sql2struct.SourceMap) *fyne.Container {
)
}
resultBox := widget.NewMultiLineEntry()
resultBox.SetPlaceHolder(`准备就绪`)
resultBox.SetPlaceHolder(``)
var tables = widget.NewTabContainer()
var currentTable = make(chan *widget.TabItem)
if tbs, err := Sql2struct.DBMetas(nil, Sql2struct.Configs().ExcludeTables, Sql2struct.Configs().TryComplete); err == nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/app/toolbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func ToolBar(win fyne.Window, ipBox *widget.TabContainer, options *Sql2struct.SQ
widget.NewToolbarAction(icon.Insert, func() {
w := fyne.CurrentApp().NewWindow("添加连接")
w.SetContent(widget.NewScrollContainer(
sql2struct.DataBase(w, ipBox, options, nil)),
sql2struct.DataBase(win, w, ipBox, options, nil)),
)
w.Resize(fyne.Size{Width: 650, Height: 300})
w.CenterOnScreen()
Expand Down Expand Up @@ -116,7 +116,7 @@ func ToolBar(win fyne.Window, ipBox *widget.TabContainer, options *Sql2struct.SQ
w.SetContent(widget.NewLabelWithStyle(`错误的连接参数`, fyne.TextAlignCenter, fyne.TextStyle{Bold: true}))
} else {
w.SetContent(widget.NewScrollContainer(
sql2struct.DataBase(w, ipBox, options, dbIndex)))
sql2struct.DataBase(win, w, ipBox, options, dbIndex)))
}
w.Resize(fyne.Size{Width: 650, Height: 300})
w.CenterOnScreen()
Expand Down
30 changes: 21 additions & 9 deletions pkg/Sql2struct/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@ import (
"strings"
)

func InStringSlice(f string, a []string) bool {
for _, s := range a {
if f == s {
return true
}
}
return false
}

func getTypeAndImports(column *core.Column) (t string) {
t = sqlType2TypeString(column.SQLType)
if Configs().Tinyint2bool && strings.HasPrefix(column.Name, "is_") &&
Expand All @@ -23,3 +14,24 @@ func getTypeAndImports(column *core.Column) (t string) {
}
return
}

func RmDuplicateElement(keywords []string) []string {
result := make([]string, 0, len(keywords))
temp := map[string]struct{}{}
for _, item := range keywords {
if _, ok := temp[item]; !ok {
temp[item] = struct{}{}
result = append(result, item)
}
}
return result
}

func InStringSlice(f string, a []string) bool {
for _, s := range a {
if f == s {
return true
}
}
return false
}

0 comments on commit c4281a5

Please sign in to comment.