Add batch support to RPC endpoint queries
This commit is contained in:
parent
d7469c30d5
commit
d5a947bf53
1 changed files with 34 additions and 6 deletions
40
web/rpc.go
40
web/rpc.go
|
@ -35,11 +35,15 @@ func (r *rpc) Query(c *fibre.Context, sql string, vars map[string]interface{}) (
|
|||
}
|
||||
|
||||
func (r *rpc) Select(c *fibre.Context, class string, thing interface{}) (interface{}, error) {
|
||||
switch thing.(type) {
|
||||
switch thing := thing.(type) {
|
||||
case *fibre.RPCNull:
|
||||
return db.Execute(c, "SELECT * FROM $class", map[string]interface{}{
|
||||
"class": sql.NewTable(class),
|
||||
})
|
||||
case []interface{}:
|
||||
return db.Execute(c, "SELECT * FROM $batch", map[string]interface{}{
|
||||
"batch": sql.NewBatch(class, thing),
|
||||
})
|
||||
default:
|
||||
return db.Execute(c, "SELECT * FROM $thing", map[string]interface{}{
|
||||
"thing": sql.NewThing(class, thing),
|
||||
|
@ -48,12 +52,17 @@ func (r *rpc) Select(c *fibre.Context, class string, thing interface{}) (interfa
|
|||
}
|
||||
|
||||
func (r *rpc) Create(c *fibre.Context, class string, thing interface{}, data map[string]interface{}) (interface{}, error) {
|
||||
switch thing.(type) {
|
||||
switch thing := thing.(type) {
|
||||
case *fibre.RPCNull:
|
||||
return db.Execute(c, "CREATE $class CONTENT $data RETURN AFTER", map[string]interface{}{
|
||||
"class": sql.NewTable(class),
|
||||
"data": data,
|
||||
})
|
||||
case []interface{}:
|
||||
return db.Execute(c, "CREATE $batch CONTENT $data RETURN AFTER", map[string]interface{}{
|
||||
"batch": sql.NewBatch(class, thing),
|
||||
"data": data,
|
||||
})
|
||||
default:
|
||||
return db.Execute(c, "CREATE $thing CONTENT $data RETURN AFTER", map[string]interface{}{
|
||||
"thing": sql.NewThing(class, thing),
|
||||
|
@ -63,12 +72,17 @@ func (r *rpc) Create(c *fibre.Context, class string, thing interface{}, data map
|
|||
}
|
||||
|
||||
func (r *rpc) Update(c *fibre.Context, class string, thing interface{}, data map[string]interface{}) (interface{}, error) {
|
||||
switch thing.(type) {
|
||||
switch thing := thing.(type) {
|
||||
case *fibre.RPCNull:
|
||||
return db.Execute(c, "UPDATE $class CONTENT $data RETURN AFTER", map[string]interface{}{
|
||||
"class": sql.NewTable(class),
|
||||
"data": data,
|
||||
})
|
||||
case []interface{}:
|
||||
return db.Execute(c, "UPDATE $batch CONTENT $data RETURN AFTER", map[string]interface{}{
|
||||
"batch": sql.NewBatch(class, thing),
|
||||
"data": data,
|
||||
})
|
||||
default:
|
||||
return db.Execute(c, "UPDATE $thing CONTENT $data RETURN AFTER", map[string]interface{}{
|
||||
"thing": sql.NewThing(class, thing),
|
||||
|
@ -78,12 +92,17 @@ func (r *rpc) Update(c *fibre.Context, class string, thing interface{}, data map
|
|||
}
|
||||
|
||||
func (r *rpc) Change(c *fibre.Context, class string, thing interface{}, data map[string]interface{}) (interface{}, error) {
|
||||
switch thing.(type) {
|
||||
switch thing := thing.(type) {
|
||||
case *fibre.RPCNull:
|
||||
return db.Execute(c, "UPDATE $class MERGE $data RETURN AFTER", map[string]interface{}{
|
||||
"class": sql.NewTable(class),
|
||||
"data": data,
|
||||
})
|
||||
case []interface{}:
|
||||
return db.Execute(c, "UPDATE $batch MERGE $data RETURN AFTER", map[string]interface{}{
|
||||
"batch": sql.NewBatch(class, thing),
|
||||
"data": data,
|
||||
})
|
||||
default:
|
||||
return db.Execute(c, "UPDATE $thing MERGE $data RETURN AFTER", map[string]interface{}{
|
||||
"thing": sql.NewThing(class, thing),
|
||||
|
@ -93,12 +112,17 @@ func (r *rpc) Change(c *fibre.Context, class string, thing interface{}, data map
|
|||
}
|
||||
|
||||
func (r *rpc) Modify(c *fibre.Context, class string, thing interface{}, data map[string]interface{}) (interface{}, error) {
|
||||
switch thing.(type) {
|
||||
switch thing := thing.(type) {
|
||||
case *fibre.RPCNull:
|
||||
return db.Execute(c, "UPDATE $class DIFF $data RETURN AFTER", map[string]interface{}{
|
||||
"class": sql.NewTable(class),
|
||||
"data": data,
|
||||
})
|
||||
case []interface{}:
|
||||
return db.Execute(c, "UPDATE $batch DIFF $data RETURN AFTER", map[string]interface{}{
|
||||
"batch": sql.NewBatch(class, thing),
|
||||
"data": data,
|
||||
})
|
||||
default:
|
||||
return db.Execute(c, "UPDATE $thing DIFF $data RETURN AFTER", map[string]interface{}{
|
||||
"thing": sql.NewThing(class, thing),
|
||||
|
@ -108,11 +132,15 @@ func (r *rpc) Modify(c *fibre.Context, class string, thing interface{}, data map
|
|||
}
|
||||
|
||||
func (r *rpc) Delete(c *fibre.Context, class string, thing interface{}) (interface{}, error) {
|
||||
switch thing.(type) {
|
||||
switch thing := thing.(type) {
|
||||
case *fibre.RPCNull:
|
||||
return db.Execute(c, "DELETE $class", map[string]interface{}{
|
||||
"class": sql.NewTable(class),
|
||||
})
|
||||
case []interface{}:
|
||||
return db.Execute(c, "DELETE $batch", map[string]interface{}{
|
||||
"batch": sql.NewBatch(class, thing),
|
||||
})
|
||||
default:
|
||||
return db.Execute(c, "DELETE $thing", map[string]interface{}{
|
||||
"thing": sql.NewThing(class, thing),
|
||||
|
|
Loading…
Reference in a new issue