database/api2sql/execute_test.go

75 lines
1.8 KiB
Go
Raw Normal View History

2024-08-23 17:54:48 +08:00
// Package api2sql ...
//
// Description : api2sql ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2024-08-23 17:36
package api2sql
import (
2024-08-23 18:17:31 +08:00
"context"
"encoding/json"
2024-08-23 18:17:31 +08:00
"fmt"
"git.zhangdeman.cn/zhangdeman/consts"
2024-08-23 17:54:48 +08:00
"git.zhangdeman.cn/zhangdeman/database"
"git.zhangdeman.cn/zhangdeman/database/define"
"reflect"
2024-08-23 17:54:48 +08:00
"testing"
)
func Test_execute_Run(t *testing.T) {
clientManager := database.NewWrapperClient()
if err := clientManager.AddWithConfig("TEST_DATABASE", nil, &define.Database{
Master: &define.Driver{
DBType: "sqlite3",
Host: "/tmp/gateway.db",
},
Slave: &define.Driver{
DBType: "sqlite3",
Host: "/tmp/gateway.db",
},
}, []string{}); nil != err {
panic(err.Error())
}
2024-08-23 18:17:31 +08:00
dbClient, _ := clientManager.GetDBClient("TEST_DATABASE")
dbClient.SetTableStructure(map[string][]*define.ColumnConfig{
"project": []*define.ColumnConfig{
&define.ColumnConfig{
Column: "flag",
Alias: "project_flag",
Type: "string",
},
},
})
2024-08-23 17:54:48 +08:00
Exec.SetDatabaseClientManager(clientManager)
2024-08-23 18:17:31 +08:00
res, err := Exec.List(context.Background(), &define.Api2SqlParam{
2024-08-23 18:23:37 +08:00
DatabaseFlag: "TEST_DATABASE",
Table: "project",
ForceMaster: false,
InputSql: "",
TableSplitConfig: define.TableSplitConfig{},
SqlType: consts.SqlTypeList,
ColumnList: []*define.ColumnConfig{
&define.ColumnConfig{
Column: "flag",
Alias: "project_flag",
Type: "string",
},
},
2024-08-23 18:17:31 +08:00
Limit: 0,
Offset: 0,
ForceNoLimit: false,
OrderField: "id",
OrderRule: "desc",
WithCount: false,
ConditionList: nil,
TableColumnConfig: nil,
Tx: nil,
})
byteData, _ := json.Marshal(res)
tt := reflect.TypeOf(res)
fmt.Println(tt.String(), res, err, string(byteData))
2024-08-23 17:54:48 +08:00
}