update in
This commit is contained in:
parent
dafbdbf168
commit
994ac48b8e
3 changed files with 120 additions and 2 deletions
|
|
@ -162,6 +162,39 @@ func TestProcessDeleteWhere(t *testing.T) {
|
||||||
capsule.Query().Table("service").Where("id", id).Delete()
|
capsule.Query().Table("service").Where("id", id).Delete()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestProcessDeleteIn(t *testing.T) {
|
||||||
|
args := []interface{}{
|
||||||
|
"service",
|
||||||
|
map[string]interface{}{
|
||||||
|
"name": "腾讯黑岩云主机",
|
||||||
|
"short_name": "高性能云主机",
|
||||||
|
"kind_id": 3,
|
||||||
|
"manu_id": 1,
|
||||||
|
"price_options": []string{"按月订阅"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
process := gou.NewProcess("xiang.table.Save", args...)
|
||||||
|
response := table.ProcessSave(process)
|
||||||
|
assert.NotNil(t, response)
|
||||||
|
assert.True(t, any.Of(response).IsInt())
|
||||||
|
|
||||||
|
id := any.Of(response).CInt()
|
||||||
|
args = []interface{}{
|
||||||
|
"service",
|
||||||
|
any.Of(response).Int(),
|
||||||
|
"id",
|
||||||
|
}
|
||||||
|
process = gou.NewProcess("xiang.table.DeleteIn", args...)
|
||||||
|
response = table.ProcessDeleteIn(process)
|
||||||
|
|
||||||
|
assert.NotNil(t, response)
|
||||||
|
assert.True(t, any.Of(response).IsInt())
|
||||||
|
assert.Equal(t, any.Of(response).CInt(), 1)
|
||||||
|
|
||||||
|
// 清空数据
|
||||||
|
capsule.Query().Table("service").Where("id", id).Delete()
|
||||||
|
}
|
||||||
|
|
||||||
func TestProcessUpdateWhere(t *testing.T) {
|
func TestProcessUpdateWhere(t *testing.T) {
|
||||||
args := []interface{}{
|
args := []interface{}{
|
||||||
"service",
|
"service",
|
||||||
|
|
@ -201,6 +234,42 @@ func TestProcessUpdateWhere(t *testing.T) {
|
||||||
capsule.Query().Table("service").Where("id", id).Delete()
|
capsule.Query().Table("service").Where("id", id).Delete()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestProcessUpdateIn(t *testing.T) {
|
||||||
|
args := []interface{}{
|
||||||
|
"service",
|
||||||
|
map[string]interface{}{
|
||||||
|
"name": "腾讯黑岩云主机",
|
||||||
|
"short_name": "高性能云主机",
|
||||||
|
"kind_id": 3,
|
||||||
|
"manu_id": 1,
|
||||||
|
"price_options": []string{"按月订阅"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
process := gou.NewProcess("xiang.table.Save", args...)
|
||||||
|
response := table.ProcessSave(process)
|
||||||
|
assert.NotNil(t, response)
|
||||||
|
assert.True(t, any.Of(response).IsInt())
|
||||||
|
|
||||||
|
id := any.Of(response).CInt()
|
||||||
|
args = []interface{}{
|
||||||
|
"service",
|
||||||
|
id,
|
||||||
|
"id",
|
||||||
|
map[string]interface{}{
|
||||||
|
"name": "腾讯黑岩云主机UP",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
process = gou.NewProcess("xiang.table.UpdateIn", args...)
|
||||||
|
response = table.ProcessUpdateIn(process)
|
||||||
|
|
||||||
|
assert.NotNil(t, response)
|
||||||
|
assert.True(t, any.Of(response).IsInt())
|
||||||
|
assert.Equal(t, any.Of(response).CInt(), 1)
|
||||||
|
|
||||||
|
// 清空数据
|
||||||
|
capsule.Query().Table("service").Where("id", id).Delete()
|
||||||
|
}
|
||||||
|
|
||||||
func TestProcessSetting(t *testing.T) {
|
func TestProcessSetting(t *testing.T) {
|
||||||
args := []interface{}{"service", ""}
|
args := []interface{}{"service", ""}
|
||||||
process := gou.NewProcess("xiang.table.Setting", args...)
|
process := gou.NewProcess("xiang.table.Setting", args...)
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ func init() {
|
||||||
gou.RegisterProcessHandler("xiang.table.Insert", ProcessInsert)
|
gou.RegisterProcessHandler("xiang.table.Insert", ProcessInsert)
|
||||||
gou.RegisterProcessHandler("xiang.table.UpdateWhere", ProcessUpdateWhere)
|
gou.RegisterProcessHandler("xiang.table.UpdateWhere", ProcessUpdateWhere)
|
||||||
gou.RegisterProcessHandler("xiang.table.DeleteWhere", ProcessDeleteWhere)
|
gou.RegisterProcessHandler("xiang.table.DeleteWhere", ProcessDeleteWhere)
|
||||||
|
gou.RegisterProcessHandler("xiang.table.UpdateIn", ProcessUpdateIn)
|
||||||
|
gou.RegisterProcessHandler("xiang.table.DeleteIn", ProcessDeleteIn)
|
||||||
gou.RegisterProcessHandler("xiang.table.Setting", ProcessSetting)
|
gou.RegisterProcessHandler("xiang.table.Setting", ProcessSetting)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -105,6 +107,30 @@ func ProcessDeleteWhere(process *gou.Process) interface{} {
|
||||||
return gou.NewProcess(api.Process, param).Run()
|
return gou.NewProcess(api.Process, param).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProcessDeleteIn xiang.table.DeleteIn
|
||||||
|
// 按条件批量删除数据, 请求成功返回删除行数
|
||||||
|
func ProcessDeleteIn(process *gou.Process) interface{} {
|
||||||
|
|
||||||
|
process.ValidateArgNums(3)
|
||||||
|
name := process.ArgsString(0)
|
||||||
|
table := Select(name)
|
||||||
|
api := table.APIs["delete-in"].ValidateLoop("xiang.table.DeleteIn")
|
||||||
|
if process.NumOfArgsIs(4) && api.IsAllow(process.Args[3]) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 批量删除
|
||||||
|
ids := strings.Split(process.ArgsString(1), ",")
|
||||||
|
primary := process.ArgsString(2, "id")
|
||||||
|
param := gou.QueryParam{
|
||||||
|
Wheres: []gou.QueryWhere{
|
||||||
|
{Column: primary, OP: "in", Value: ids},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return gou.NewProcess(api.Process, param).Run()
|
||||||
|
}
|
||||||
|
|
||||||
// ProcessUpdateWhere xiang.table.UpdateWhere
|
// ProcessUpdateWhere xiang.table.UpdateWhere
|
||||||
// 按条件批量更新数据, 请求成功返回更新行数
|
// 按条件批量更新数据, 请求成功返回更新行数
|
||||||
func ProcessUpdateWhere(process *gou.Process) interface{} {
|
func ProcessUpdateWhere(process *gou.Process) interface{} {
|
||||||
|
|
@ -125,6 +151,29 @@ func ProcessUpdateWhere(process *gou.Process) interface{} {
|
||||||
return gou.NewProcess(api.Process, param, process.Args[2]).Run()
|
return gou.NewProcess(api.Process, param, process.Args[2]).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProcessUpdateIn xiang.table.UpdateWhere
|
||||||
|
// 按条件批量更新数据, 请求成功返回更新行数
|
||||||
|
func ProcessUpdateIn(process *gou.Process) interface{} {
|
||||||
|
|
||||||
|
process.ValidateArgNums(4)
|
||||||
|
name := process.ArgsString(0)
|
||||||
|
table := Select(name)
|
||||||
|
api := table.APIs["update-in"].ValidateLoop("xiang.table.UpdateIn")
|
||||||
|
if process.NumOfArgsIs(5) && api.IsAllow(process.Args[4]) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 批量删除
|
||||||
|
ids := strings.Split(process.ArgsString(1), ",")
|
||||||
|
primary := process.ArgsString(2, "id")
|
||||||
|
param := gou.QueryParam{
|
||||||
|
Wheres: []gou.QueryWhere{
|
||||||
|
{Column: primary, OP: "in", Value: ids},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return gou.NewProcess(api.Process, param, process.Args[3]).Run()
|
||||||
|
}
|
||||||
|
|
||||||
// ProcessInsert xiang.table.Insert
|
// ProcessInsert xiang.table.Insert
|
||||||
// 插入多条数据记录,请求成功返回插入行数
|
// 插入多条数据记录,请求成功返回插入行数
|
||||||
func ProcessInsert(process *gou.Process) interface{} {
|
func ProcessInsert(process *gou.Process) interface{} {
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@
|
||||||
"path": "/:name/delete/in",
|
"path": "/:name/delete/in",
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
"process": "xiang.table.DeleteIn",
|
"process": "xiang.table.DeleteIn",
|
||||||
"in": ["$param.name", "$query.ids", ":payload"],
|
"in": ["$param.name", "$query.ids", "$query.primary"],
|
||||||
"out": {
|
"out": {
|
||||||
"status": 200,
|
"status": 200,
|
||||||
"type": "application/json"
|
"type": "application/json"
|
||||||
|
|
@ -89,7 +89,7 @@
|
||||||
"path": "/:name/update/in",
|
"path": "/:name/update/in",
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
"process": "xiang.table.UpdateIn",
|
"process": "xiang.table.UpdateIn",
|
||||||
"in": ["$param.name", "$query.ids", ":payload"],
|
"in": ["$param.name", "$query.ids", "$query.primary", ":payload"],
|
||||||
"out": {
|
"out": {
|
||||||
"status": 200,
|
"status": 200,
|
||||||
"type": "application/json"
|
"type": "application/json"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue