From ac95aa1bcd74a133ad966cc2ef568b3b6378c959 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Tue, 31 Jan 2017 12:19:56 +0000 Subject: [PATCH] Remove javascript language runtime --- cli/setup.go | 15 --------------- cli/start.go | 2 -- cnf/cnf.go | 1 - util/item/each.go | 46 ++++++++++------------------------------------ 4 files changed, 10 insertions(+), 54 deletions(-) diff --git a/cli/setup.go b/cli/setup.go index 5a7c5a61..2d497887 100644 --- a/cli/setup.go +++ b/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 // -------------------------------------------------- diff --git a/cli/start.go b/cli/start.go index 1a34c8c2..49ce9498 100644 --- a/cli/start.go +++ b/cli/start.go @@ -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")) diff --git a/cnf/cnf.go b/cnf/cnf.go index 49fb8a77..02261838 100644 --- a/cnf/cnf.go +++ b/cnf/cnf.go @@ -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 diff --git a/util/item/each.go b/util/item/each.go index 52908a43..d0ed7495 100644 --- a/util/item/each.go +++ b/util/item/each.go @@ -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) } }