Skip to content

Commit 6e21e2a

Browse files
committed
Update property
1 parent c4b8321 commit 6e21e2a

3 files changed

Lines changed: 24 additions & 24 deletions

File tree

benchmark_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,45 +162,45 @@ func BenchmarkJson2Sql_Union_BuildRaw(b *testing.B) {
162162
var newData = "[" + jsonData + "," + jsonData + "]"
163163

164164
for i := 0; i < b.N; i++ {
165-
jql, _ := NewJson2Sql([]byte(newData), &Json2SqlConf{withUnion: true})
165+
jql, _ := NewJson2Sql([]byte(newData), &Json2SqlConf{WithUnion: true})
166166
jql.BuildUnion()
167167
}
168168
}
169169

170170
func BenchmarkJson2Sql_Union_Generate(b *testing.B) {
171171
var newData = "[" + jsonData + "," + jsonData + "]"
172172
for i := 0; i < b.N; i++ {
173-
jql, _ := NewJson2Sql([]byte(newData), &Json2SqlConf{withUnion: true})
173+
jql, _ := NewJson2Sql([]byte(newData), &Json2SqlConf{WithUnion: true})
174174
jql.GenerateUnion()
175175
}
176176
}
177177

178178
func BenchmarkJson2Sql_BuildRaw_WithSanitizedSQLi(b *testing.B) {
179179
for i := 0; i < b.N; i++ {
180-
jql, _ := NewJson2Sql([]byte(jsonData), &Json2SqlConf{withSanitizedInjection: true})
180+
jql, _ := NewJson2Sql([]byte(jsonData), &Json2SqlConf{WithSanitizedInjection: true})
181181
jql.Build()
182182
}
183183
}
184184

185185
func BenchmarkJson2Sql_Generate_WithSanitizedSQLi(b *testing.B) {
186186
for i := 0; i < b.N; i++ {
187-
jql, _ := NewJson2Sql([]byte(jsonData), &Json2SqlConf{withSanitizedInjection: true})
187+
jql, _ := NewJson2Sql([]byte(jsonData), &Json2SqlConf{WithSanitizedInjection: true})
188188
jql.Generate()
189189
}
190190
}
191191

192192
func BenchmarkJson2Sql_Union_BuildRaw_WithSanitizedSQLi(b *testing.B) {
193193
var newData = "[" + jsonData + "," + jsonData + "]"
194194
for i := 0; i < b.N; i++ {
195-
jql, _ := NewJson2Sql([]byte(newData), &Json2SqlConf{withSanitizedInjection: true, withUnion: true})
195+
jql, _ := NewJson2Sql([]byte(newData), &Json2SqlConf{WithSanitizedInjection: true, WithUnion: true})
196196
jql.BuildUnion()
197197
}
198198
}
199199

200200
func BenchmarkJson2Sql_Union_Generate_WithSanitizedSQLi(b *testing.B) {
201201
var newData = "[" + jsonData + "," + jsonData + "]"
202202
for i := 0; i < b.N; i++ {
203-
jql, _ := NewJson2Sql([]byte(newData), &Json2SqlConf{withSanitizedInjection: true, withUnion: true})
203+
jql, _ := NewJson2Sql([]byte(newData), &Json2SqlConf{WithSanitizedInjection: true, WithUnion: true})
204204
jql.GenerateUnion()
205205
}
206206
}

jql.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
)
1212

1313
type Json2SqlConf struct {
14-
withUnion bool
15-
withSanitizedInjection bool
14+
WithUnion bool
15+
WithSanitizedInjection bool
1616
}
1717
type Json2Sql struct {
1818
sqlJson *SQLJson
@@ -24,7 +24,7 @@ func NewJson2Sql(jsonData []byte, conf *Json2SqlConf) (*Json2Sql, error) {
2424
var sqlJson *SQLJson
2525
var sqlJsonUnion *[]SQLJson
2626

27-
if conf != nil && conf.withUnion {
27+
if conf != nil && conf.WithUnion {
2828

2929
err := json.Unmarshal(jsonData, &sqlJsonUnion)
3030
if err != nil {
@@ -185,7 +185,7 @@ func (jql *Json2Sql) GenerateSelectFrom(selection ...json.RawMessage) string {
185185
if sqlSelectDetail.SubQuery != nil {
186186
jsonBytes, _ := json.Marshal(*sqlSelectDetail.SubQuery)
187187

188-
jql, _ := NewJson2Sql(jsonBytes, &Json2SqlConf{withSanitizedInjection: jql.config.withSanitizedInjection})
188+
jql, _ := NewJson2Sql(jsonBytes, &Json2SqlConf{WithSanitizedInjection: jql.config.WithSanitizedInjection})
189189

190190
field = fmt.Sprintf("(%s) AS %s", jql.rawBuild(), *sqlSelectDetail.Alias)
191191

@@ -218,7 +218,7 @@ func (jql *Json2Sql) GenerateSelectFrom(selection ...json.RawMessage) string {
218218
if isSelectExpect {
219219
if selectExpect.SubQuery != nil {
220220
jsonBytes, _ := json.Marshal(*selectExpect.SubQuery)
221-
jql, _ := NewJson2Sql(jsonBytes, &Json2SqlConf{withSanitizedInjection: jql.config.withSanitizedInjection})
221+
jql, _ := NewJson2Sql(jsonBytes, &Json2SqlConf{WithSanitizedInjection: jql.config.WithSanitizedInjection})
222222
defaultValue = fmt.Sprintf("(%s)", jql.rawBuild())
223223
}
224224
}
@@ -355,7 +355,7 @@ func (jql *Json2Sql) GenerateConditions(conditions ...Condition) string {
355355
if isSelectSub {
356356
if selectSub.SubQuery != nil {
357357
jsonBytes, _ := json.Marshal(*selectSub.SubQuery)
358-
jql, _ := NewJson2Sql(jsonBytes, &Json2SqlConf{withSanitizedInjection: jql.config.withSanitizedInjection})
358+
jql, _ := NewJson2Sql(jsonBytes, &Json2SqlConf{WithSanitizedInjection: jql.config.WithSanitizedInjection})
359359
expression = string(condition.Operator) + " " + fmt.Sprintf("(%s)", jql.rawBuild())
360360
}
361361
}
@@ -379,7 +379,7 @@ func (jql *Json2Sql) GenerateConditions(conditions ...Condition) string {
379379
if isSelectExpect {
380380
if selectExpect.SubQuery != nil {
381381
jsonBytes, _ := json.Marshal(*selectExpect.SubQuery)
382-
jql, _ := NewJson2Sql(jsonBytes, &Json2SqlConf{withSanitizedInjection: jql.config.withSanitizedInjection})
382+
jql, _ := NewJson2Sql(jsonBytes, &Json2SqlConf{WithSanitizedInjection: jql.config.WithSanitizedInjection})
383383
expect = fmt.Sprintf("(%s)", jql.rawBuild())
384384
}
385385
}
@@ -440,7 +440,7 @@ func (jql *Json2Sql) rawBuild() string {
440440
func (jql *Json2Sql) Build() string {
441441
sqlCleanValue := jql.rawValueExtractor(jql.concateQueryString())
442442

443-
if jql.config != nil && jql.config.withSanitizedInjection && !isValidSQL(sqlCleanValue) {
443+
if jql.config != nil && jql.config.WithSanitizedInjection && !isValidSQL(sqlCleanValue) {
444444
return "Invalid sql string you've got sanitized SQL string"
445445
}
446446

@@ -450,7 +450,7 @@ func (jql *Json2Sql) Build() string {
450450
func (jql *Json2Sql) Generate() (string, []interface{}, error) {
451451
sql := jql.rawBuild()
452452

453-
if jql.config != nil && jql.config.withSanitizedInjection && !isValidSQL(sql) {
453+
if jql.config != nil && jql.config.WithSanitizedInjection && !isValidSQL(sql) {
454454
return "", nil, fmt.Errorf("error: %s", "Invalid sql string you've got sanitized SQL string")
455455
}
456456

@@ -480,7 +480,7 @@ func (jql *Json2Sql) buildRawUnion() string {
480480
func (jql *Json2Sql) BuildUnion() string {
481481
sqlCleanValue := jql.rawValueExtractor(jql.buildRawUnion())
482482

483-
if jql.config != nil && jql.config.withSanitizedInjection && !isValidSQL(sqlCleanValue) {
483+
if jql.config != nil && jql.config.WithSanitizedInjection && !isValidSQL(sqlCleanValue) {
484484
return "Invalid sql string you've got sanitized SQL string"
485485
}
486486

@@ -490,7 +490,7 @@ func (jql *Json2Sql) BuildUnion() string {
490490
func (jql *Json2Sql) GenerateUnion() (string, []interface{}, error) {
491491
sql := jql.buildRawUnion()
492492

493-
if jql.config != nil && jql.config.withSanitizedInjection && !isValidSQL(sql) {
493+
if jql.config != nil && jql.config.WithSanitizedInjection && !isValidSQL(sql) {
494494
return "", nil, fmt.Errorf("error: %s", "Invalid sql string you've got sanitized SQL string")
495495
}
496496

jql_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestConstructor_Fail(t *testing.T) {
2020
}
2121

2222
func TestConstructor_Fail_Union(t *testing.T) {
23-
var _, err = NewJson2Sql([]byte(`[{"table":"test"`), &Json2SqlConf{withUnion: true})
23+
var _, err = NewJson2Sql([]byte(`[{"table":"test"`), &Json2SqlConf{WithUnion: true})
2424
assert.NotNil(t, err)
2525
}
2626

@@ -1158,7 +1158,7 @@ func TestBuildRawUnion(t *testing.T) {
11581158
]
11591159
`
11601160

1161-
jql, _ := NewJson2Sql([]byte(jsonData), &Json2SqlConf{withUnion: true})
1161+
jql, _ := NewJson2Sql([]byte(jsonData), &Json2SqlConf{WithUnion: true})
11621162
sql := jql.BuildUnion()
11631163

11641164
strExpectation := "SELECT a, b, table_1.b AS foo_bar, (SELECT a, b FROM table_4 WHERE a = 1 LIMIT 1) AS baz FROM table_1 WHERE a = 1 LIMIT 1 UNION SELECT a, b, table_1.b AS foo_bar, (SELECT a, b FROM table_4 WHERE a = 1 LIMIT 1) AS baz FROM table_2 WHERE a = 1 LIMIT 1"
@@ -1204,7 +1204,7 @@ func TestGenerateUnion(t *testing.T) {
12041204
]
12051205
`
12061206

1207-
jql, _ := NewJson2Sql([]byte(jsonData), &Json2SqlConf{withUnion: true})
1207+
jql, _ := NewJson2Sql([]byte(jsonData), &Json2SqlConf{WithUnion: true})
12081208
sql, filter, _ := jql.GenerateUnion()
12091209

12101210
strExpectation := "SELECT a, b FROM table_1 WHERE a = ? LIMIT 1 UNION SELECT a, b FROM table_2 WHERE a = ? LIMIT 1"
@@ -1233,7 +1233,7 @@ func TestGenerateBuild_PreventInjection(t *testing.T) {
12331233
}
12341234
`
12351235

1236-
jql, _ := NewJson2Sql([]byte(jsonData), &Json2SqlConf{withSanitizedInjection: true})
1236+
jql, _ := NewJson2Sql([]byte(jsonData), &Json2SqlConf{WithSanitizedInjection: true})
12371237
sql := jql.Build()
12381238

12391239
strExpectation := "Invalid sql string you've got sanitized SQL string"
@@ -1261,7 +1261,7 @@ func TestGenerate_PreventInjection(t *testing.T) {
12611261
}
12621262
`
12631263

1264-
jql, _ := NewJson2Sql([]byte(jsonData), &Json2SqlConf{withSanitizedInjection: true})
1264+
jql, _ := NewJson2Sql([]byte(jsonData), &Json2SqlConf{WithSanitizedInjection: true})
12651265
_, _, err := jql.Generate()
12661266

12671267
assert.NotNil(t, err)
@@ -1305,7 +1305,7 @@ func TestGenerateBuildUnion_PreventInjection(t *testing.T) {
13051305
]
13061306
`
13071307

1308-
jql, _ := NewJson2Sql([]byte(jsonData), &Json2SqlConf{withSanitizedInjection: true, withUnion: true})
1308+
jql, _ := NewJson2Sql([]byte(jsonData), &Json2SqlConf{WithSanitizedInjection: true, WithUnion: true})
13091309
sql := jql.BuildUnion()
13101310

13111311
strExpectation := "Invalid sql string you've got sanitized SQL string"
@@ -1351,7 +1351,7 @@ func TestGenerateUnion_PreventInjection(t *testing.T) {
13511351
]
13521352
`
13531353

1354-
jql, _ := NewJson2Sql([]byte(jsonData), &Json2SqlConf{withSanitizedInjection: true, withUnion: true})
1354+
jql, _ := NewJson2Sql([]byte(jsonData), &Json2SqlConf{WithSanitizedInjection: true, WithUnion: true})
13551355
_, _, err := jql.GenerateUnion()
13561356

13571357
assert.NotNil(t, err)

0 commit comments

Comments
 (0)