mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-05-13 17:29:46 +08:00
- MariaDB:MySQL驱动占位,默认端口3306,归类关系型数据库 - Vastbase(海量):PG驱动占位,默认端口5432,归类国产数据库 - HighGo(瀚高):PG驱动,支持SM3认证扩展,归类国产数据库 - MongoDB:官方驱动实现,归类NoSQL - SQL Server:微软官方驱动实现,归类关系型数据库 - ConnectionModal 新增数据源选项卡与默认端口配置 - database.go 新增5种类型的实例化分支 - 同步更新 db_context、methods_db、sql_sanitize、methods_file、sql_helpers 类型判断 - 新增 HighGo SM3 驱动集成指南
63 lines
1.7 KiB
Go
63 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 "vastbase":
|
|
return &VastbaseDB{}, 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)
|
|
}
|
|
}
|