mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-05-13 04:39:44 +08:00
- 新增 SphinxDB 驱动注册并复用 MySQL 协议连接 - 前端新增 sphinx 连接类型与默认端口 9306 - 函数/视图/触发器改为多语句回退查询与版本探测提示 - 后端对不支持能力返回稳定降级结果
67 lines
1.7 KiB
Go
67 lines
1.7 KiB
Go
package db
|
|
|
|
import (
|
|
"GoNavi-Wails/internal/connection"
|
|
"fmt"
|
|
)
|
|
|
|
type Database interface {
|
|
Connect(config connection.ConnectionConfig) error
|
|
Close() error
|
|
Ping() error
|
|
Query(query string) ([]map[string]interface{}, []string, error)
|
|
Exec(query string) (int64, error)
|
|
GetDatabases() ([]string, error)
|
|
GetTables(dbName string) ([]string, error)
|
|
GetCreateStatement(dbName, tableName string) (string, error)
|
|
GetColumns(dbName, tableName string) ([]connection.ColumnDefinition, error)
|
|
GetAllColumns(dbName string) ([]connection.ColumnDefinitionWithTable, error)
|
|
GetIndexes(dbName, tableName string) ([]connection.IndexDefinition, error)
|
|
GetForeignKeys(dbName, tableName string) ([]connection.ForeignKeyDefinition, error)
|
|
GetTriggers(dbName, tableName string) ([]connection.TriggerDefinition, error)
|
|
}
|
|
|
|
type BatchApplier interface {
|
|
ApplyChanges(tableName string, changes connection.ChangeSet) error
|
|
}
|
|
|
|
// Factory
|
|
func NewDatabase(dbType string) (Database, error) {
|
|
switch dbType {
|
|
case "mysql":
|
|
return &MySQLDB{}, nil
|
|
case "postgres":
|
|
return &PostgresDB{}, nil
|
|
case "sqlite":
|
|
return &SQLiteDB{}, nil
|
|
case "oracle":
|
|
return &OracleDB{}, nil
|
|
case "dameng":
|
|
return &DamengDB{}, nil
|
|
case "kingbase":
|
|
return &KingbaseDB{}, nil
|
|
case "mongodb":
|
|
return &MongoDB{}, nil
|
|
case "sqlserver":
|
|
return &SqlServerDB{}, nil
|
|
case "highgo":
|
|
return &HighGoDB{}, nil
|
|
case "mariadb":
|
|
return &MariaDB{}, nil
|
|
case "sphinx":
|
|
return &SphinxDB{}, nil
|
|
case "vastbase":
|
|
return &VastbaseDB{}, nil
|
|
case "tdengine":
|
|
return &TDengineDB{}, nil
|
|
case "custom":
|
|
return &CustomDB{}, nil
|
|
default:
|
|
// Default to MySQL for backward compatibility if empty
|
|
if dbType == "" {
|
|
return &MySQLDB{}, nil
|
|
}
|
|
return nil, fmt.Errorf("unsupported database type: %s", dbType)
|
|
}
|
|
}
|