Browse Source

Add DeleteProc.

develop
Mingcai SHEN 8 years ago
parent
commit
212bac2e22
1 changed files with 4 additions and 3 deletions
  1. +4
    -3
      restlet/curd.go

+ 4
- 3
restlet/curd.go View File

@ -20,8 +20,9 @@ import (
*/
type InsertEntityProc func(entity interface{}) error
type UpdateEntityProc func(entity interface{}) ([]string, error)
type DeleteEntityProc func(params ...utils.HashMap) error
func MakeCURDRestletHandle(table *xql.Table, entity interface{}, init_func func(*xql.Table, RequestContext), inertfunc InsertEntityProc, updatefunc UpdateEntityProc, pks ...string) RestletHandleFunc {
func MakeCURDRestletHandle(table *xql.Table, entity interface{}, init_func func(*xql.Table, RequestContext), inertfunc InsertEntityProc, updatefunc UpdateEntityProc, deletefunc DeleteEntityProc, pks ...string) RestletHandleFunc {
if len(pks) != len(table.PrimaryKey) {
log.Debugln("MakeCURDRestletHandle:>", table.TableName, table.PrimaryKey, pks)
panic("Primary Key num not matched as defined in table."+table.TableName)
@ -29,7 +30,7 @@ func MakeCURDRestletHandle(table *xql.Table, entity interface{}, init_func func(
getter := _make_get_handle(table, entity, pks...)
poster := _make_post_handle(table, entity, inertfunc, pks...)
patcher := _make_put_or_patch_handle(table, entity, updatefunc, pks...)
deleter := _make_delete_handle(table, entity, pks...)
deleter := _make_delete_handle(table, entity, deletefunc, pks...)
f := func(ctx RequestContext, url_params utils.HashMap, queries utils.HashMap, post_data []byte) (*RestletResult, error) {
init_func(table, ctx)
switch ctx.Request().Method {
@ -276,7 +277,7 @@ func _make_post_handle(table *xql.Table, entity interface{}, inertfunc InsertEnt
}
func _make_delete_handle(table *xql.Table, entity interface{}, pks...string) RestletHandleFunc {
func _make_delete_handle(table *xql.Table, entity interface{}, deletefunc DeleteEntityProc, pks...string) RestletHandleFunc {
f := func(ctx RequestContext, url_params utils.HashMap, queries utils.HashMap, post_data []byte) (result *RestletResult, err error) {
session := xql.MakeSession(ctx.SQL(), "postgres", true)
defer session.Close()

Loading…
Cancel
Save