mirror of
https://github.com/FlipsideCrypto/flip-rpc-client-go.git
synced 2026-02-06 10:56:45 +00:00
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package flip
|
|
|
|
import (
|
|
"github.com/FlipsideCrypto/flip-rpc-client-go/dynamicquery"
|
|
"github.com/mitchellh/mapstructure"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// ExecuteDynamicQueryResponse returns the RPC response
|
|
type ExecuteDynamicQueryResponse struct {
|
|
Results []interface{} `mapstructure:"results"`
|
|
ResultCount int `mapstructure:"result_count"`
|
|
CompiledSQL string `mapstructure:"compiled_sql"`
|
|
Error string `mapstructure:"error,omitempty"`
|
|
}
|
|
|
|
// ExecuteDynamicQuery returns the query results
|
|
func (c Client) ExecuteDynamicQuery(query dynamicquery.Query, debug bool) (*ExecuteDynamicQueryResponse, error) {
|
|
var input = make(map[string]interface{})
|
|
input["query"] = query
|
|
input["debug"] = debug
|
|
|
|
var response ExecuteDynamicQueryResponse
|
|
|
|
rpc, err := c.CallRPC("RPCService.ExecuteDynamicQuery", input)
|
|
|
|
if err != nil {
|
|
return &response, err
|
|
}
|
|
|
|
err = mapstructure.Decode(rpc.Result, &response)
|
|
if err != nil {
|
|
return &response, errors.Wrap(err, "error decoding into `ExecuteDynamicQueryResponse`")
|
|
}
|
|
response.Error = rpc.Error
|
|
|
|
return &response, nil
|
|
}
|