Browse Source

添加sql执行

yjp 1 năm trước cách đây
mục cha
commit
9ba4dbfc82

+ 1 - 0
project/server/application/service/service.go

@@ -14,6 +14,7 @@ type Service interface {
 var RegisteredServices = []Service{
 	versionService,
 	configurationService,
+	sqlExecutorService,
 	classService,
 	studentService,
 	identityService,

+ 27 - 0
project/server/application/service/sql_executor.go

@@ -0,0 +1,27 @@
+package service
+
+import (
+	"git.sxidc.com/go-framework/baize/convenient/domain/sql_executor"
+	"git.sxidc.com/go-framework/baize/framework/binding"
+	"git.sxidc.com/go-framework/baize/framework/core/api"
+	"git.sxidc.com/go-framework/baize/framework/core/application"
+)
+
+var sqlExecutorService = &SqlExecutorService{}
+
+type SqlExecutorService struct{}
+
+func (svc *SqlExecutorService) Init(appInstance *application.App) error {
+	svc.prefixRoot(appInstance)
+	return nil
+}
+
+func (svc *SqlExecutorService) Destroy() error {
+	return nil
+}
+
+func (svc *SqlExecutorService) prefixRoot(appInstance *application.App) {
+	prefixRootBinder := binding.NewBinder(appInstance.ChooseRouter(api.RouterPrefix, ""), appInstance.Infrastructure())
+
+	sql_executor.BindSqlExecutor(prefixRootBinder, &sql_executor.Simple{Schema: dbSchema})
+}

+ 17 - 0
project/server/deployment/data_service/data_containers/sql_executor.yaml

@@ -0,0 +1,17 @@
+kind: DataContainer
+spec:
+  namespace: baize
+  data_source: baize
+  name: test.sql_execute_logs
+  spec:
+    table_name: test.sql_execute_logs
+    columns:
+      - name: sql
+        type: text
+        comment: sql语句
+      - name: executor_name
+        type: varchar(256)
+        comment: 执行人姓名
+      - name: executed_time
+        type: "timestamp with time zone"
+        comment: 执行时间

+ 4 - 0
project/server/main.go

@@ -77,6 +77,10 @@ import (
 // curl -X POST -H "Content-Type: application/json" -d '{"id":"42b305bb292c4082a3e91a2967f11111", "studentIds": ["00254b4a7102429db35e6edc8e47a764"]}' "http://localhost:31000/example/api/v1/hobby/student/update"
 // curl -X GET "http://localhost:31000/example/api/v1/hobby/student/query?id=42b305bb292c4082a3e91a2967f11111"
 
+// Sql Executor
+// curl -X POST -H 'Content-Type: application/json' -d '{"sql": "SELECT * FROM test.sql_execute_logs", "executorName": "test"}' "http://localhost:31000/example/api/sql/execute"
+// curl -X GET "http://localhost:31000/example/api/sql/execute/log?sql=SELECT&executorName=te&startExecuteTime=2024-05-30%2012:03:45"
+
 func main() {
 	application.NewApp()
 	defer application.DestroyApp()