|
|
@@ -19,7 +19,10 @@ import (
|
|
19
|
19
|
"git.x2erp.com/qdy/go-base/webx/router"
|
|
20
|
20
|
|
|
21
|
21
|
"git.x2erp.com/qdy/go-db/factory/database"
|
|
|
22
|
+ "git.x2erp.com/qdy/go-db/sqldef"
|
|
22
|
23
|
mcpsdk "github.com/modelcontextprotocol/go-sdk/mcp"
|
|
|
24
|
+
|
|
|
25
|
+ _ "git.x2erp.com/qdy/go-svc-mcp/internal/tables" // 导入表定义包,触发 init() 函数
|
|
23
|
26
|
)
|
|
24
|
27
|
|
|
25
|
28
|
var (
|
|
|
@@ -45,6 +48,8 @@ func main() {
|
|
45
|
48
|
// 3. 创建数据库工厂
|
|
46
|
49
|
dbFactory := container.Create(ctr, database.CreateDBFactory)
|
|
47
|
50
|
dbFactory.TestConnection()
|
|
|
51
|
+ // 创建表
|
|
|
52
|
+ creteTabel(dbFactory)
|
|
48
|
53
|
|
|
49
|
54
|
// 创建mongodb
|
|
50
|
55
|
//mongoDBFactory := container.Create(ctr, mongodb.CreateFactory)
|
|
|
@@ -117,3 +122,23 @@ func createMcpService(cfg config.IConfig, dbFactory *database.DBFactory) *mcp.Se
|
|
117
|
122
|
|
|
118
|
123
|
return mcpServer
|
|
119
|
124
|
}
|
|
|
125
|
+
|
|
|
126
|
+func creteTabel(factory *database.DBFactory) {
|
|
|
127
|
+
|
|
|
128
|
+ // 获取数据库连接和类型
|
|
|
129
|
+ db := factory.GetDB()
|
|
|
130
|
+ dbType := factory.GetDBType()
|
|
|
131
|
+
|
|
|
132
|
+ // 创建表同步器
|
|
|
133
|
+ syncer, err := sqldef.NewTableSyncer(db, dbType)
|
|
|
134
|
+ if err != nil {
|
|
|
135
|
+ log.Printf("创建 - 建立器失败: %v", err)
|
|
|
136
|
+ }
|
|
|
137
|
+
|
|
|
138
|
+ // 创建表
|
|
|
139
|
+ if err := syncer.CreateTables(); err != nil {
|
|
|
140
|
+ log.Printf("建表失败: %v", err)
|
|
|
141
|
+ }
|
|
|
142
|
+
|
|
|
143
|
+ log.Println("数据库表建立完成!")
|
|
|
144
|
+}
|