From d614da537d129d37b14a4d6130dd626297b51fc5 Mon Sep 17 00:00:00 2001 From: Yusuf Papurcu Date: Tue, 8 Jun 2021 09:50:37 +0300 Subject: [PATCH] (dev): execute.go changes I did execute functions private and more understandable. Also byte array return is default now. --- execute.go | 10 +++++----- filterbuilder.go | 15 +++++++-------- querybuilder.go | 8 ++++++-- transformbuilder.go | 8 ++++++-- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/execute.go b/execute.go index 5374d8b..fcda795 100644 --- a/execute.go +++ b/execute.go @@ -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 } @@ -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) } diff --git a/filterbuilder.go b/filterbuilder.go index b5337e7..05b44f3 100644 --- a/filterbuilder.go +++ b/filterbuilder.go @@ -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 { @@ -135,7 +134,7 @@ 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 } @@ -143,8 +142,8 @@ func (f *FilterBuilder) ContainsObject(column string, value interface{}) *Filter 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 } diff --git a/querybuilder.go b/querybuilder.go index 68bdf4d..aba80bb 100644 --- a/querybuilder.go +++ b/querybuilder.go @@ -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 { diff --git a/transformbuilder.go b/transformbuilder.go index 66c95ce..f4a8157 100644 --- a/transformbuilder.go +++ b/transformbuilder.go @@ -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 {