Remove javascript language runtime
This commit is contained in:
parent
b49ae370f6
commit
ac95aa1bcd
4 changed files with 10 additions and 54 deletions
15
cli/setup.go
15
cli/setup.go
|
@ -105,21 +105,6 @@ func setup() {
|
|||
log.Fatal("Specify a valid PEM encoded private key file.")
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
// Lang
|
||||
// --------------------------------------------------
|
||||
|
||||
// Ensure that the default
|
||||
// language options are set
|
||||
|
||||
if opts.DB.Lang == "" {
|
||||
opts.DB.Lang = "lua"
|
||||
}
|
||||
|
||||
if opts.DB.Lang != "js" && opts.DB.Lang != "lua" {
|
||||
log.Fatal("Specify a valid runtime language. Valid languages are js, or lua.")
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
// Auth
|
||||
// --------------------------------------------------
|
||||
|
|
|
@ -79,8 +79,6 @@ func init() {
|
|||
startCmd.PersistentFlags().StringVar(&opts.DB.Cert.Key, "db-key", "", "Path to the private key file used to connect to the remote database.")
|
||||
startCmd.PersistentFlags().StringVar(&opts.DB.Path, "db-path", "", flag("db"))
|
||||
|
||||
startCmd.PersistentFlags().StringVarP(&opts.DB.Lang, "language", "l", "lua", "The runtime language to use.")
|
||||
|
||||
startCmd.PersistentFlags().StringVarP(&opts.Cluster.Join, "join", "j", "", flag("join"))
|
||||
|
||||
startCmd.PersistentFlags().StringVarP(&opts.DB.Code, "key", "k", "", flag("key"))
|
||||
|
|
|
@ -38,7 +38,6 @@ type Options struct {
|
|||
Host string // Surreal host to connect to
|
||||
Port string // Surreal port to connect to
|
||||
Base string // Base key to use in KV stores
|
||||
Lang string // Base key to use in KV stores
|
||||
Cert struct {
|
||||
CA string
|
||||
Crt string
|
||||
|
|
|
@ -18,10 +18,8 @@ import (
|
|||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"github.com/robertkrimen/otto"
|
||||
"github.com/yuin/gopher-lua"
|
||||
|
||||
"github.com/abcum/surreal/cnf"
|
||||
"github.com/abcum/surreal/sql"
|
||||
"github.com/abcum/surreal/util/conv"
|
||||
)
|
||||
|
@ -39,45 +37,21 @@ func (this *Doc) each(fld *sql.DefineFieldStatement) (err error) {
|
|||
|
||||
if fld.Code != "" {
|
||||
|
||||
if cnf.Settings.DB.Lang == "js" {
|
||||
vm := lua.NewState()
|
||||
defer vm.Close()
|
||||
|
||||
vm := otto.New()
|
||||
|
||||
vm.Set("doc", this.current.Copy())
|
||||
|
||||
ret, err := vm.Run("(function() { " + fld.Code + " })()")
|
||||
if err != nil {
|
||||
return fmt.Errorf("Problem executing code: %v %v", fld.Code, err.Error())
|
||||
}
|
||||
|
||||
if ret.IsUndefined() {
|
||||
this.current.Del(key)
|
||||
} else {
|
||||
val, _ := ret.Export()
|
||||
this.current.Set(val, key)
|
||||
}
|
||||
vm.SetGlobal("doc", toLUA(vm, this.current.Copy()))
|
||||
|
||||
if err := vm.DoString(fld.Code); err != nil {
|
||||
return fmt.Errorf("Problem executing code: %v %v", fld.Code, err.Error())
|
||||
}
|
||||
|
||||
if cnf.Settings.DB.Lang == "lua" {
|
||||
|
||||
vm := lua.NewState()
|
||||
defer vm.Close()
|
||||
|
||||
vm.SetGlobal("doc", toLUA(vm, this.current.Copy()))
|
||||
|
||||
if err := vm.DoString(fld.Code); err != nil {
|
||||
return fmt.Errorf("Problem executing code: %v %v", fld.Code, err.Error())
|
||||
}
|
||||
|
||||
ret := vm.Get(-1)
|
||||
|
||||
if ret == lua.LNil {
|
||||
this.current.Del(key)
|
||||
} else {
|
||||
this.current.Set(frLUA(ret), key)
|
||||
}
|
||||
ret := vm.Get(-1)
|
||||
|
||||
if ret == lua.LNil {
|
||||
this.current.Del(key)
|
||||
} else {
|
||||
this.current.Set(frLUA(ret), key)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue