Remove javascript language runtime

This commit is contained in:
Tobie Morgan Hitchcock 2017-01-31 12:19:56 +00:00
parent b49ae370f6
commit ac95aa1bcd
4 changed files with 10 additions and 54 deletions

View file

@ -105,21 +105,6 @@ func setup() {
log.Fatal("Specify a valid PEM encoded private key file.") 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 // Auth
// -------------------------------------------------- // --------------------------------------------------

View file

@ -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.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().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.Cluster.Join, "join", "j", "", flag("join"))
startCmd.PersistentFlags().StringVarP(&opts.DB.Code, "key", "k", "", flag("key")) startCmd.PersistentFlags().StringVarP(&opts.DB.Code, "key", "k", "", flag("key"))

View file

@ -38,7 +38,6 @@ type Options struct {
Host string // Surreal host to connect to Host string // Surreal host to connect to
Port string // Surreal port to connect to Port string // Surreal port to connect to
Base string // Base key to use in KV stores Base string // Base key to use in KV stores
Lang string // Base key to use in KV stores
Cert struct { Cert struct {
CA string CA string
Crt string Crt string

View file

@ -18,10 +18,8 @@ import (
"fmt" "fmt"
"regexp" "regexp"
"github.com/robertkrimen/otto"
"github.com/yuin/gopher-lua" "github.com/yuin/gopher-lua"
"github.com/abcum/surreal/cnf"
"github.com/abcum/surreal/sql" "github.com/abcum/surreal/sql"
"github.com/abcum/surreal/util/conv" "github.com/abcum/surreal/util/conv"
) )
@ -39,45 +37,21 @@ func (this *Doc) each(fld *sql.DefineFieldStatement) (err error) {
if fld.Code != "" { if fld.Code != "" {
if cnf.Settings.DB.Lang == "js" { vm := lua.NewState()
defer vm.Close()
vm := otto.New() vm.SetGlobal("doc", toLUA(vm, this.current.Copy()))
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)
}
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" { ret := vm.Get(-1)
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)
}
if ret == lua.LNil {
this.current.Del(key)
} else {
this.current.Set(frLUA(ret), key)
} }
} }