Skip to content

Commit bd578fe

Browse files
committed
Update constructor
1 parent c9ef383 commit bd578fe

4 files changed

Lines changed: 35 additions & 191 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
coverage.txt

coverage.txt

Lines changed: 0 additions & 160 deletions
This file was deleted.

jql.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ type Json2Sql struct {
1111
sqlJson *SQLJson
1212
}
1313

14-
func NewJson2Sql(jsonData json.RawMessage) *Json2Sql {
14+
func NewJson2Sql(jsonData json.RawMessage) (*Json2Sql, error) {
1515
var sqlJson *SQLJson
1616

1717
err := json.Unmarshal(jsonData, &sqlJson)
1818

1919
if err != nil {
20-
return nil
20+
return nil, fmt.Errorf("error: %s", err)
2121
}
2222

23-
return &Json2Sql{sqlJson}
23+
return &Json2Sql{sqlJson}, nil
2424
}
2525

2626
func cleanSpaces(input string) string {
@@ -117,7 +117,8 @@ func (jql *Json2Sql) GenerateSelectFrom(selection ...json.RawMessage) string {
117117

118118
if sqlSelectDetail.SubQuery != nil {
119119
jsonBytes, _ := json.Marshal(*sqlSelectDetail.SubQuery)
120-
jql := NewJson2Sql(jsonBytes)
120+
jql, _ := NewJson2Sql(jsonBytes)
121+
121122
field = fmt.Sprintf("(%s) AS %s", jql.Build(), *sqlSelectDetail.Alias)
122123
}
123124
}
@@ -143,7 +144,7 @@ func (jql *Json2Sql) GenerateSelectFrom(selection ...json.RawMessage) string {
143144
if isSelectExpect {
144145
if selectExpect.SubQuery != nil {
145146
jsonBytes, _ := json.Marshal(*selectExpect.SubQuery)
146-
jql := NewJson2Sql(jsonBytes)
147+
jql, _ := NewJson2Sql(jsonBytes)
147148
defaultValue = fmt.Sprintf("(%s)", jql.Build())
148149
}
149150
}
@@ -280,7 +281,7 @@ func (jql *Json2Sql) GenerateConditions(conditions ...Condition) string {
280281
if isSelectSub {
281282
if selectSub.SubQuery != nil {
282283
jsonBytes, _ := json.Marshal(*selectSub.SubQuery)
283-
jql := NewJson2Sql(jsonBytes)
284+
jql, _ := NewJson2Sql(jsonBytes)
284285
expression = string(condition.Operator) + " " + fmt.Sprintf("(%s)", jql.Build())
285286
}
286287
}
@@ -304,7 +305,7 @@ func (jql *Json2Sql) GenerateConditions(conditions ...Condition) string {
304305
if isSelectExpect {
305306
if selectExpect.SubQuery != nil {
306307
jsonBytes, _ := json.Marshal(*selectExpect.SubQuery)
307-
jql := NewJson2Sql(jsonBytes)
308+
jql, _ := NewJson2Sql(jsonBytes)
308309
expect = fmt.Sprintf("(%s)", jql.Build())
309310
}
310311
}

0 commit comments

Comments
 (0)