| 48 | } |
| 49 | |
| 50 | func processCommonArgs(qa *queryArgs, args []js.Value) (err js.Value) { |
| 51 | if len(args) == 0 { |
| 52 | return |
| 53 | } |
| 54 | vars := args[0] |
| 55 | |
| 56 | if vars.Type() != js.TypeObject && |
| 57 | vars.Type() != js.TypeNull && |
| 58 | vars.Type() != js.TypeUndefined { |
| 59 | err = toJSError( |
| 60 | errors.New("variables argument can only be a string or null")) |
| 61 | return |
| 62 | } |
| 63 | |
| 64 | if vars.Type() == js.TypeObject { |
| 65 | val := js.Global().Get("JSON").Call("stringify", vars) |
| 66 | qa.vars = json.RawMessage(val.String()) |
| 67 | } |
| 68 | |
| 69 | if len(args) == 1 { |
| 70 | return |
| 71 | } |
| 72 | opts := args[1] |
| 73 | |
| 74 | if opts.Type() != js.TypeObject && |
| 75 | opts.Type() != js.TypeNull && |
| 76 | opts.Type() != js.TypeUndefined { |
| 77 | err = toJSError( |
| 78 | errors.New("options argument can only be a object or null")) |
| 79 | return |
| 80 | } |
| 81 | |
| 82 | if v := opts.Get("userID"); v.Type() == js.TypeString || v.Type() == js.TypeNumber { |
| 83 | qa.userID = optVal(v) |
| 84 | } |
| 85 | return |
| 86 | } |
| 87 | |
| 88 | // func toTx(dbType string, val js.Value) *sql.Tx { |
| 89 | // switch dbType { |