|
@@ -65,6 +65,11 @@ func ApiV1(binding *http_binding.Binding, dpsAddress string, operatorIDFunc Oper
|
|
|
Path: "/dpsv1/database/operate",
|
|
|
ResponseFunc: response.SendMsgResponse,
|
|
|
BusinessFunc: func(c *binding_context.Context, inputModel OperateRequest) (any, error) {
|
|
|
+ version := "v1"
|
|
|
+ if utils.IsStringNotEmpty(inputModel.Version) {
|
|
|
+ version = inputModel.Version
|
|
|
+ }
|
|
|
+
|
|
|
operatorID, err := operatorIDFunc(c)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
@@ -84,13 +89,13 @@ func ApiV1(binding *http_binding.Binding, dpsAddress string, operatorIDFunc Oper
|
|
|
for _, parsedClause := range parsedClauses {
|
|
|
switch clause := parsedClause.(type) {
|
|
|
case *insertClause:
|
|
|
- return doInsert(tx, inputModel, clause, operatorID)
|
|
|
+ return doInsert(tx, version, clause, operatorID)
|
|
|
case *deleteClause:
|
|
|
- return doDelete(tx, inputModel, clause, operatorID)
|
|
|
+ return doDelete(tx, version, clause, operatorID)
|
|
|
case *updateClause:
|
|
|
- return doUpdate(tx, inputModel, clause, operatorID)
|
|
|
+ return doUpdate(tx, version, clause, operatorID)
|
|
|
case *selectClause:
|
|
|
- return doSelect(dpsClient, inputModel, clause)
|
|
|
+ return doSelect(dpsClient, version, clause)
|
|
|
default:
|
|
|
return errors.New("不支持的SQL语句")
|
|
|
}
|
|
@@ -121,7 +126,10 @@ func insertMap(clause *insertClause) map[string]any {
|
|
|
}
|
|
|
|
|
|
func deleteMap(clause *deleteClause) map[string]any {
|
|
|
- return map[string]any{}
|
|
|
+ return map[string]any{
|
|
|
+ "table": clause.table,
|
|
|
+ "where": clause.where,
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
func updateMap(clause *updateClause) map[string]any {
|
|
@@ -132,12 +140,7 @@ func selectMap(clause *selectClause) map[string]any {
|
|
|
return map[string]any{}
|
|
|
}
|
|
|
|
|
|
-func doInsert(tx client.Transaction, inputModel OperateRequest, clause *insertClause, operatorID string) error {
|
|
|
- version := inputModel.Version
|
|
|
- if utils.IsStringEmpty(version) {
|
|
|
- version = "v1"
|
|
|
- }
|
|
|
-
|
|
|
+func doInsert(tx client.Transaction, version string, clause *insertClause, operatorID string) error {
|
|
|
tableRow := client.NewTableRow()
|
|
|
for columnName, value := range clause.tableRows {
|
|
|
switch value.kind {
|
|
@@ -158,7 +161,7 @@ func doInsert(tx client.Transaction, inputModel OperateRequest, clause *insertCl
|
|
|
|
|
|
statement, err := tx.InsertTx(&client.InsertRequest{
|
|
|
TablePrefixWithSchema: clause.table,
|
|
|
- Version: inputModel.Version,
|
|
|
+ Version: version,
|
|
|
KeyColumns: clause.keyColumns,
|
|
|
TableRow: tableRow,
|
|
|
UserID: operatorID,
|
|
@@ -171,29 +174,14 @@ func doInsert(tx client.Transaction, inputModel OperateRequest, clause *insertCl
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func doDelete(tx client.Transaction, inputModel OperateRequest, clause *deleteClause, operatorID string) error {
|
|
|
- version := inputModel.Version
|
|
|
- if utils.IsStringEmpty(version) {
|
|
|
- version = "v1"
|
|
|
- }
|
|
|
-
|
|
|
+func doDelete(tx client.Transaction, version string, clause *deleteClause, operatorID string) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func doUpdate(tx client.Transaction, inputModel OperateRequest, clause *updateClause, operatorID string) error {
|
|
|
- version := inputModel.Version
|
|
|
- if utils.IsStringEmpty(version) {
|
|
|
- version = "v1"
|
|
|
- }
|
|
|
-
|
|
|
+func doUpdate(tx client.Transaction, version string, clause *updateClause, operatorID string) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func doSelect(dpsClient client.Client, inputModel OperateRequest, clause *selectClause) error {
|
|
|
- version := inputModel.Version
|
|
|
- if utils.IsStringEmpty(version) {
|
|
|
- version = "v1"
|
|
|
- }
|
|
|
-
|
|
|
+func doSelect(dpsClient client.Client, version string, clause *selectClause) error {
|
|
|
return nil
|
|
|
}
|