75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
// Package api2sql ...
|
|
//
|
|
// Description : api2sql ...
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 2024-08-23 17:36
|
|
package api2sql
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"git.zhangdeman.cn/zhangdeman/consts"
|
|
"git.zhangdeman.cn/zhangdeman/database"
|
|
"git.zhangdeman.cn/zhangdeman/database/define"
|
|
"reflect"
|
|
"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())
|
|
}
|
|
dbClient, _ := clientManager.GetDBClient("TEST_DATABASE")
|
|
|
|
dbClient.SetTableStructure(map[string][]*define.ColumnConfig{
|
|
"project": []*define.ColumnConfig{
|
|
&define.ColumnConfig{
|
|
Column: "flag",
|
|
Alias: "project_flag",
|
|
Type: "string",
|
|
},
|
|
},
|
|
})
|
|
Exec.SetDatabaseClientManager(clientManager)
|
|
res, err := Exec.List(context.Background(), &define.Api2SqlParam{
|
|
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",
|
|
},
|
|
},
|
|
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))
|
|
}
|