Skip to content

Commit

Permalink
(dev): execute.go changes
Browse files Browse the repository at this point in the history
I did execute functions private and more understandable. Also byte array return is default now.
  • Loading branch information
yusufpapurcu committed Jun 8, 2021
1 parent 8527b28 commit d614da5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
10 changes: 5 additions & 5 deletions execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
)

func ExecuteHelper(client *Client, method string, body []byte) ([]byte, error) {
func executeHelper(client *Client, method string, body []byte) ([]byte, error) {
if client.ClientError != nil {
return nil, client.ClientError
}
Expand All @@ -33,11 +33,11 @@ func ExecuteHelper(client *Client, method string, body []byte) ([]byte, error) {
return respbody, nil
}

func Execute(client *Client, method string, body []byte) (string, error) {
resp, err := ExecuteHelper(client, method, body)
func executeString(client *Client, method string, body []byte) (string, error) {
resp, err := executeHelper(client, method, body)
return string(resp), err
}

func ExecuteReturnByteArray(client *Client, method string, body []byte) ([]byte, error) {
return ExecuteHelper(client, method, body)
func execute(client *Client, method string, body []byte) ([]byte, error) {
return executeHelper(client, method, body)
}
15 changes: 7 additions & 8 deletions filterbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ type FilterBuilder struct {
body []byte
}

func (f *FilterBuilder) Execute() (string, error) {
return Execute(f.client, f.method, f.body)
func (f *FilterBuilder) ExecuteString() (string, error) {
return executeString(f.client, f.method, f.body)
}

func (f *FilterBuilder) ExecuteReturnByteArray() ([]byte, error) {
return ExecuteReturnByteArray(f.client, f.method, f.body)
func (f *FilterBuilder) Execute() ([]byte, error) {
return execute(f.client, f.method, f.body)
}

var filterOperators = []string{"eq", "neq", "gt", "gte", "lt", "lte", "like", "ilike", "is", "in", "cs", "cd", "sl", "sr", "nxl", "nxr", "adj", "ov", "fts", "plfts", "phfts", "wfts"}


func isOperator(value string) bool {
for _, operator := range filterOperators {
if value == operator {
Expand Down Expand Up @@ -135,16 +134,16 @@ func (f *FilterBuilder) ContainedBy(column string, value []string) *FilterBuilde
}

func (f *FilterBuilder) ContainsObject(column string, value interface{}) *FilterBuilder {
sum , err := json.Marshal(value)
sum, err := json.Marshal(value)
if err != nil {
f.client.ClientError = err
}
f.client.clientTransport.params.Add(column, "cs."+string(sum))
return f
}

func (f *FilterBuilder) ContainedByObject(column string, value interface{}) *FilterBuilder{
sum , err := json.Marshal(value)
func (f *FilterBuilder) ContainedByObject(column string, value interface{}) *FilterBuilder {
sum, err := json.Marshal(value)
if err != nil {
f.client.ClientError = err
}
Expand Down
8 changes: 6 additions & 2 deletions querybuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ type QueryBuilder struct {
body []byte
}

func (q *QueryBuilder) Execute() (string, error) {
return Execute(q.client, q.method, q.body)
func (q *QueryBuilder) ExecuteString() (string, error) {
return executeString(q.client, q.method, q.body)
}

func (q *QueryBuilder) Execute() ([]byte, error) {
return execute(q.client, q.method, q.body)
}

func (q *QueryBuilder) Select(columns, count string, head bool) *FilterBuilder {
Expand Down
8 changes: 6 additions & 2 deletions transformbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ type TransformBuilder struct {
body []byte
}

func (t *TransformBuilder) Execute() (string, error) {
return Execute(t.client, t.method, t.body)
func (t *TransformBuilder) ExecuteString() (string, error) {
return executeString(t.client, t.method, t.body)
}

func (t *TransformBuilder) Execute() ([]byte, error) {
return execute(t.client, t.method, t.body)
}

func (t *TransformBuilder) Limit(count int, foreignTable string) *TransformBuilder {
Expand Down

0 comments on commit d614da5

Please sign in to comment.