mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-06-21 14:04:01 +08:00
- 后端新增 saved_queries.json 仓库,保存、导入、删除和重绑统一走 Wails 方法 - 启动时导入旧 lite-db-storage 中的 savedQueries 和连接快照,成功后清理旧字段 - 新增连接指纹匹配,唯一强匹配自动重绑,歧义场景保留为未匹配 - 侧边栏新增未匹配已存查询分组,并支持手动绑定到目标连接 - 前端保存、重命名、删除查询改为后端持久化,并补充浏览器 mock - 补充后端与前端迁移回归测试
65 lines
1.8 KiB
Go
65 lines
1.8 KiB
Go
package app
|
|
|
|
import "GoNavi-Wails/internal/connection"
|
|
|
|
func (a *App) savedQueryRepository() *savedQueryRepository {
|
|
return newSavedQueryRepository(a.configDir)
|
|
}
|
|
|
|
func (a *App) GetSavedQueries() ([]connection.SavedQuery, error) {
|
|
savedQueriesMu.Lock()
|
|
defer savedQueriesMu.Unlock()
|
|
|
|
queries, err := a.savedQueryRepository().load()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
currentConnections, err := a.savedConnectionRepository().List()
|
|
if err != nil {
|
|
return queries, nil
|
|
}
|
|
return resolveSavedQueryBindings(queries, currentConnections, nil), nil
|
|
}
|
|
|
|
func (a *App) SaveQuery(input connection.SavedQuery) (connection.SavedQuery, error) {
|
|
currentConnections, err := a.savedConnectionRepository().List()
|
|
if err == nil {
|
|
input = resolveSavedQueryBindings([]connection.SavedQuery{input}, currentConnections, nil)[0]
|
|
}
|
|
return a.savedQueryRepository().Save(input)
|
|
}
|
|
|
|
func (a *App) ImportSavedQueries(payload connection.SavedQueryImportPayload) ([]connection.SavedQuery, error) {
|
|
currentConnections, err := a.savedConnectionRepository().List()
|
|
if err != nil {
|
|
currentConnections = nil
|
|
}
|
|
return a.savedQueryRepository().Import(payload, currentConnections)
|
|
}
|
|
|
|
func (a *App) DeleteQuery(id string) error {
|
|
return a.savedQueryRepository().Delete(id)
|
|
}
|
|
|
|
func (a *App) RebindSavedQuery(id string, connectionID string) (connection.SavedQuery, error) {
|
|
target, err := a.savedConnectionRepository().Find(connectionID)
|
|
if err != nil {
|
|
return connection.SavedQuery{}, err
|
|
}
|
|
return a.savedQueryRepository().Rebind(id, target)
|
|
}
|
|
|
|
func (a *App) GetUnboundSavedQueries() ([]connection.SavedQuery, error) {
|
|
queries, err := a.GetSavedQueries()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
result := make([]connection.SavedQuery, 0)
|
|
for _, query := range queries {
|
|
if query.BindingStatus == savedQueryBindingOrphan {
|
|
result = append(result, query)
|
|
}
|
|
}
|
|
return result, nil
|
|
}
|