Ensure all db.executor methods are private
This commit is contained in:
parent
3167be73bb
commit
b68c33835e
8 changed files with 28 additions and 26 deletions
|
@ -26,7 +26,7 @@ func (e *executor) executeCreateStatement(ast *sql.CreateStatement) (out []inter
|
|||
|
||||
for k, w := range ast.What {
|
||||
if what, ok := w.(*sql.Param); ok {
|
||||
ast.What[k] = e.Get(what.ID)
|
||||
ast.What[k] = e.get(what.ID)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
6
db/db.go
6
db/db.go
|
@ -160,11 +160,9 @@ func Process(ctx *fibre.Context, ast *sql.Query, vars map[string]interface{}) (o
|
|||
// details, and the current runtime variables
|
||||
// and execute the queries within.
|
||||
|
||||
exec := pool.Get().(*executor)
|
||||
exec := newExec(ast, ctx, vars)
|
||||
|
||||
defer pool.Put(exec)
|
||||
|
||||
exec.Reset(ast, ctx, vars)
|
||||
defer exec.done()
|
||||
|
||||
go exec.execute(quit, recv)
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ func (e *executor) executeDeleteStatement(ast *sql.DeleteStatement) (out []inter
|
|||
|
||||
for k, w := range ast.What {
|
||||
if what, ok := w.(*sql.Param); ok {
|
||||
ast.What[k] = e.Get(what.ID)
|
||||
ast.What[k] = e.get(what.ID)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,34 +24,38 @@ import (
|
|||
"github.com/abcum/surreal/util/data"
|
||||
)
|
||||
|
||||
var pool sync.Pool
|
||||
|
||||
func init() {
|
||||
|
||||
pool.New = func() interface{} {
|
||||
var executors = sync.Pool{
|
||||
New: func() interface{} {
|
||||
return &executor{}
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
type executor struct {
|
||||
txn kvs.TX
|
||||
ctx *data.Doc
|
||||
ast *sql.Query
|
||||
mem *mem.Store
|
||||
web *fibre.Context
|
||||
txn kvs.TX
|
||||
ctx *data.Doc
|
||||
ast *sql.Query
|
||||
mem *mem.Store
|
||||
web *fibre.Context
|
||||
closed chan struct{}
|
||||
}
|
||||
|
||||
func (e *executor) Reset(ast *sql.Query, web *fibre.Context, vars map[string]interface{}) {
|
||||
func newExec(ast *sql.Query, web *fibre.Context, vars map[string]interface{}) (e *executor) {
|
||||
e = executors.Get().(*executor)
|
||||
e.ast = ast
|
||||
e.web = web
|
||||
e.ctx = data.Consume(vars)
|
||||
e.closed = make(chan struct{}, 1)
|
||||
return
|
||||
}
|
||||
|
||||
func (e *executor) Set(key string, val interface{}) {
|
||||
func (e *executor) done() {
|
||||
executors.Put(e)
|
||||
}
|
||||
|
||||
func (e *executor) set(key string, val interface{}) {
|
||||
e.ctx.Set(val, key)
|
||||
}
|
||||
|
||||
func (e *executor) Get(key string) (val interface{}) {
|
||||
func (e *executor) get(key string) (val interface{}) {
|
||||
return e.ctx.Get(key).Data()
|
||||
}
|
|
@ -22,9 +22,9 @@ func (e *executor) executeLetStatement(ast *sql.LetStatement) (out []interface{}
|
|||
|
||||
switch what := ast.What.(type) {
|
||||
default:
|
||||
e.Set(ast.Name, what)
|
||||
e.set(ast.Name, what)
|
||||
case *sql.Param:
|
||||
e.Set(ast.Name, e.Get(what.ID))
|
||||
e.set(ast.Name, e.get(what.ID))
|
||||
}
|
||||
|
||||
return
|
||||
|
|
|
@ -30,7 +30,7 @@ func (e *executor) executeReturnStatement(ast *sql.ReturnStatement) (out []inter
|
|||
case *sql.Empty:
|
||||
// Ignore
|
||||
case *sql.Param:
|
||||
out = append(out, e.Get(what.ID))
|
||||
out = append(out, e.get(what.ID))
|
||||
}
|
||||
|
||||
return
|
||||
|
|
|
@ -24,7 +24,7 @@ func (e *executor) executeSelectStatement(ast *sql.SelectStatement) (out []inter
|
|||
|
||||
for k, w := range ast.What {
|
||||
if what, ok := w.(*sql.Param); ok {
|
||||
ast.What[k] = e.Get(what.ID)
|
||||
ast.What[k] = e.get(what.ID)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ func (e *executor) executeUpdateStatement(ast *sql.UpdateStatement) (out []inter
|
|||
|
||||
for k, w := range ast.What {
|
||||
if what, ok := w.(*sql.Param); ok {
|
||||
ast.What[k] = e.Get(what.ID)
|
||||
ast.What[k] = e.get(what.ID)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue