2017-02-23 10:13:13 +00:00
|
|
|
// Copyright © 2016 Abcum Ltd
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/abcum/fibre"
|
|
|
|
"github.com/abcum/surreal/kvs"
|
|
|
|
"github.com/abcum/surreal/mem"
|
|
|
|
"github.com/abcum/surreal/sql"
|
|
|
|
"github.com/abcum/surreal/util/data"
|
|
|
|
)
|
|
|
|
|
2017-02-28 00:17:10 +00:00
|
|
|
var executors = sync.Pool{
|
|
|
|
New: func() interface{} {
|
2017-02-23 10:13:13 +00:00
|
|
|
return &executor{}
|
2017-02-28 00:17:10 +00:00
|
|
|
},
|
2017-02-23 10:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type executor struct {
|
2017-02-28 00:17:10 +00:00
|
|
|
txn kvs.TX
|
|
|
|
ctx *data.Doc
|
|
|
|
ast *sql.Query
|
|
|
|
mem *mem.Store
|
|
|
|
web *fibre.Context
|
|
|
|
closed chan struct{}
|
2017-02-23 10:13:13 +00:00
|
|
|
}
|
|
|
|
|
2017-02-28 00:17:10 +00:00
|
|
|
func newExec(ast *sql.Query, web *fibre.Context, vars map[string]interface{}) (e *executor) {
|
|
|
|
e = executors.Get().(*executor)
|
2017-02-23 10:13:13 +00:00
|
|
|
e.ast = ast
|
|
|
|
e.web = web
|
|
|
|
e.ctx = data.Consume(vars)
|
2017-02-28 00:17:10 +00:00
|
|
|
e.closed = make(chan struct{}, 1)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *executor) done() {
|
|
|
|
executors.Put(e)
|
2017-02-23 10:13:13 +00:00
|
|
|
}
|
|
|
|
|
2017-02-28 00:17:10 +00:00
|
|
|
func (e *executor) set(key string, val interface{}) {
|
2017-02-23 10:13:13 +00:00
|
|
|
e.ctx.Set(val, key)
|
|
|
|
}
|
|
|
|
|
2017-02-28 00:17:10 +00:00
|
|
|
func (e *executor) get(key string) (val interface{}) {
|
2017-02-23 10:13:13 +00:00
|
|
|
return e.ctx.Get(key).Data()
|
|
|
|
}
|