|
@@ -73,6 +73,95 @@ func TestInsert(t *testing.T) {
|
|
|
assertEqual(tableNum, resultMap["table_num"], "表数量不一致")
|
|
assertEqual(tableNum, resultMap["table_num"], "表数量不一致")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func TestInsertBatch(t *testing.T) {
|
|
|
|
|
+ initClient(t, "localhost:30170")
|
|
|
|
|
+ defer destroyClient(t)
|
|
|
|
|
+
|
|
|
|
|
+ tablePrefix := "test." + simpleUUID()[0:8]
|
|
|
|
|
+
|
|
|
|
|
+ id1 := simpleUUID()
|
|
|
|
|
+ name1 := simpleUUID()
|
|
|
|
|
+ now1 := time.Now().Local()
|
|
|
|
|
+ tableNum1 := rand.New(rand.NewSource(now1.Unix())).Intn(10)
|
|
|
|
|
+
|
|
|
|
|
+ id2 := simpleUUID()
|
|
|
|
|
+ name2 := simpleUUID()
|
|
|
|
|
+ now2 := time.Now().Local()
|
|
|
|
|
+ tableNum2 := rand.New(rand.NewSource(now2.Unix())).Intn(10)
|
|
|
|
|
+
|
|
|
|
|
+ resultsMap := make([]map[string]any, 0)
|
|
|
|
|
+
|
|
|
|
|
+ newToolKit(t).
|
|
|
|
|
+ autoMigrate(&ports.AutoMigrateRequest{
|
|
|
|
|
+ DatabaseID: "2b78141779ee432295ca371b91c5cac7",
|
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
|
+ Version: "v1",
|
|
|
|
|
+ TableModelDescribe: tableModelDescribe,
|
|
|
|
|
+ }).
|
|
|
|
|
+ insertBatch(&ports.InsertBatchRequest{
|
|
|
|
|
+ DatabaseID: "2b78141779ee432295ca371b91c5cac7",
|
|
|
|
|
+ Items: []*ports.InsertTableItem{
|
|
|
|
|
+ {
|
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
|
+ Version: "v1",
|
|
|
|
|
+ Items: []*ports.InsertItem{
|
|
|
|
|
+ {
|
|
|
|
|
+ KeyColumns: []string{"id"},
|
|
|
|
|
+ TableRow: map[string]any{
|
|
|
|
|
+ "id": id1,
|
|
|
|
|
+ "name": name1,
|
|
|
|
|
+ "time": now1,
|
|
|
|
|
+ "table_num": tableNum1,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ KeyColumns: []string{"id"},
|
|
|
|
|
+ TableRow: map[string]any{
|
|
|
|
|
+ "id": id2,
|
|
|
|
|
+ "name": name2,
|
|
|
|
|
+ "time": now2,
|
|
|
|
|
+ "table_num": tableNum2,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ UserID: "test",
|
|
|
|
|
+ }).
|
|
|
|
|
+ queryByWhereAndOrderBy(&ports.QueryByWhereAndOrderByRequest{
|
|
|
|
|
+ DatabaseID: "2b78141779ee432295ca371b91c5cac7",
|
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
|
+ Version: "v1",
|
|
|
|
|
+ Where: []ports.ColumnCompare{
|
|
|
|
|
+ {Column: "id", Value: id1, Compare: ports.CompareEqual},
|
|
|
|
|
+ {Column: "name", Value: name1, Compare: ports.CompareEqual},
|
|
|
|
|
+ {Column: "table_num", Value: tableNum1, Compare: ports.CompareEqual},
|
|
|
|
|
+ },
|
|
|
|
|
+ PageNo: 1,
|
|
|
|
|
+ PageSize: 1,
|
|
|
|
|
+ }, &resultsMap).
|
|
|
|
|
+ assertEqual(id1, resultsMap[0]["id"], "ID不一致").
|
|
|
|
|
+ assertEqual(name1, resultsMap[0]["name"], "名称不一致").
|
|
|
|
|
+ assertEqual(now1.UnixMilli(), resultsMap[0]["time"].(time.Time).Local().UnixMilli(), "时间不一致").
|
|
|
|
|
+ assertEqual(tableNum1, resultsMap[0]["table_num"], "表数量不一致").
|
|
|
|
|
+ commonQuery(&ports.CommonQueryRequest{
|
|
|
|
|
+ DatabaseID: "2b78141779ee432295ca371b91c5cac7",
|
|
|
|
|
+ TablePrefixWithSchema: tablePrefix,
|
|
|
|
|
+ Version: "v1",
|
|
|
|
|
+ Where: []ports.ColumnCompare{
|
|
|
|
|
+ {Column: "id", Value: id2, Compare: ports.CompareEqual},
|
|
|
|
|
+ {Column: "name", Value: name2, Compare: ports.CompareEqual},
|
|
|
|
|
+ {Column: "table_num", Value: tableNum2, Compare: ports.CompareEqual},
|
|
|
|
|
+ },
|
|
|
|
|
+ PageNo: 1,
|
|
|
|
|
+ PageSize: 1,
|
|
|
|
|
+ }, &resultsMap).
|
|
|
|
|
+ assertEqual(id2, resultsMap[0]["id"], "ID不一致").
|
|
|
|
|
+ assertEqual(name2, resultsMap[0]["name"], "名称不一致").
|
|
|
|
|
+ assertEqual(now2.UnixMilli(), resultsMap[0]["time"].(time.Time).Local().UnixMilli(), "时间不一致").
|
|
|
|
|
+ assertEqual(tableNum2, resultsMap[0]["table_num"], "表数量不一致")
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func TestUpdate(t *testing.T) {
|
|
func TestUpdate(t *testing.T) {
|
|
|
initClient(t, "localhost:30170")
|
|
initClient(t, "localhost:30170")
|
|
|
defer destroyClient(t)
|
|
defer destroyClient(t)
|