Skip to content

Commit

Permalink
Merge pull request #10 from nullism/speed-up-mysql-dialect
Browse files Browse the repository at this point in the history
Greatly speed up MySQL and SQL dialect replacements
  • Loading branch information
nullism authored Feb 13, 2023
2 parents 112a51f + dc2d53f commit 807385f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 60 deletions.
116 changes: 58 additions & 58 deletions coverage.out
Original file line number Diff line number Diff line change
Expand Up @@ -46,61 +46,61 @@ github.com/nullism/bqb/query.go:172.2,172.44 1 1
github.com/nullism/bqb/query.go:157.14,159.3 1 1
github.com/nullism/bqb/query.go:163.48,165.3 1 1
github.com/nullism/bqb/query.go:167.28,170.3 2 1
github.com/nullism/bqb/utils.go:33.88,34.31 1 1
github.com/nullism/bqb/utils.go:48.2,48.17 1 1
github.com/nullism/bqb/utils.go:34.31,35.21 1 1
github.com/nullism/bqb/utils.go:35.21,37.18 2 1
github.com/nullism/bqb/utils.go:40.4,40.45 1 1
github.com/nullism/bqb/utils.go:37.18,39.5 1 1
github.com/nullism/bqb/utils.go:41.9,41.48 1 1
github.com/nullism/bqb/utils.go:41.48,43.4 1 1
github.com/nullism/bqb/utils.go:43.9,43.30 1 1
github.com/nullism/bqb/utils.go:43.30,46.4 2 1
github.com/nullism/bqb/utils.go:51.59,58.27 5 1
github.com/nullism/bqb/utils.go:142.2,143.20 2 1
github.com/nullism/bqb/utils.go:147.2,148.31 2 1
github.com/nullism/bqb/utils.go:152.2,157.3 2 1
github.com/nullism/bqb/utils.go:58.27,59.26 1 1
github.com/nullism/bqb/utils.go:61.14,63.24 2 1
github.com/nullism/bqb/utils.go:67.4,67.66 1 1
github.com/nullism/bqb/utils.go:69.15,71.24 2 1
github.com/nullism/bqb/utils.go:75.4,75.22 1 1
github.com/nullism/bqb/utils.go:82.17,84.24 2 1
github.com/nullism/bqb/utils.go:88.4,88.66 1 1
github.com/nullism/bqb/utils.go:90.18,92.24 2 1
github.com/nullism/bqb/utils.go:96.4,96.22 1 1
github.com/nullism/bqb/utils.go:103.22,105.24 2 1
github.com/nullism/bqb/utils.go:109.4,109.66 1 1
github.com/nullism/bqb/utils.go:111.15,112.16 1 1
github.com/nullism/bqb/utils.go:117.4,119.40 3 1
github.com/nullism/bqb/utils.go:121.26,123.18 2 1
github.com/nullism/bqb/utils.go:126.4,127.44 2 1
github.com/nullism/bqb/utils.go:129.28,131.18 2 1
github.com/nullism/bqb/utils.go:134.4,135.44 2 1
github.com/nullism/bqb/utils.go:137.11,139.32 2 1
github.com/nullism/bqb/utils.go:63.24,66.5 2 1
github.com/nullism/bqb/utils.go:71.24,74.5 2 1
github.com/nullism/bqb/utils.go:75.22,77.5 1 1
github.com/nullism/bqb/utils.go:77.10,80.5 2 1
github.com/nullism/bqb/utils.go:84.24,87.5 2 1
github.com/nullism/bqb/utils.go:92.24,95.5 2 1
github.com/nullism/bqb/utils.go:96.22,98.5 1 1
github.com/nullism/bqb/utils.go:98.10,101.5 2 1
github.com/nullism/bqb/utils.go:105.24,108.5 2 1
github.com/nullism/bqb/utils.go:112.16,115.13 3 1
github.com/nullism/bqb/utils.go:123.18,124.55 1 1
github.com/nullism/bqb/utils.go:131.18,132.55 1 1
github.com/nullism/bqb/utils.go:143.20,144.82 1 1
github.com/nullism/bqb/utils.go:148.31,149.84 1 1
github.com/nullism/bqb/utils.go:160.52,161.27 1 1
github.com/nullism/bqb/utils.go:162.12,163.35 1 1
github.com/nullism/bqb/utils.go:165.33,166.35 1 1
github.com/nullism/bqb/utils.go:167.12,168.15 1 1
github.com/nullism/bqb/utils.go:171.3,171.36 1 1
github.com/nullism/bqb/utils.go:172.14,173.37 1 1
github.com/nullism/bqb/utils.go:174.15,175.15 1 1
github.com/nullism/bqb/utils.go:178.3,178.38 1 1
github.com/nullism/bqb/utils.go:179.11,180.21 1 1
github.com/nullism/bqb/utils.go:181.10,182.65 1 1
github.com/nullism/bqb/utils.go:168.15,170.4 1 1
github.com/nullism/bqb/utils.go:175.15,177.4 1 1
github.com/nullism/bqb/utils.go:33.88,34.40 1 1
github.com/nullism/bqb/utils.go:37.2,37.31 1 1
github.com/nullism/bqb/utils.go:49.2,49.17 1 1
github.com/nullism/bqb/utils.go:34.40,36.3 1 1
github.com/nullism/bqb/utils.go:37.31,38.21 1 1
github.com/nullism/bqb/utils.go:38.21,40.18 2 1
github.com/nullism/bqb/utils.go:43.4,43.45 1 1
github.com/nullism/bqb/utils.go:40.18,42.5 1 1
github.com/nullism/bqb/utils.go:44.9,44.30 1 1
github.com/nullism/bqb/utils.go:44.30,47.4 2 1
github.com/nullism/bqb/utils.go:52.59,59.27 5 1
github.com/nullism/bqb/utils.go:143.2,144.20 2 1
github.com/nullism/bqb/utils.go:148.2,149.31 2 1
github.com/nullism/bqb/utils.go:153.2,158.3 2 1
github.com/nullism/bqb/utils.go:59.27,60.26 1 1
github.com/nullism/bqb/utils.go:62.14,64.24 2 1
github.com/nullism/bqb/utils.go:68.4,68.66 1 1
github.com/nullism/bqb/utils.go:70.15,72.24 2 1
github.com/nullism/bqb/utils.go:76.4,76.22 1 1
github.com/nullism/bqb/utils.go:83.17,85.24 2 1
github.com/nullism/bqb/utils.go:89.4,89.66 1 1
github.com/nullism/bqb/utils.go:91.18,93.24 2 1
github.com/nullism/bqb/utils.go:97.4,97.22 1 1
github.com/nullism/bqb/utils.go:104.22,106.24 2 1
github.com/nullism/bqb/utils.go:110.4,110.66 1 1
github.com/nullism/bqb/utils.go:112.15,113.16 1 1
github.com/nullism/bqb/utils.go:118.4,120.40 3 1
github.com/nullism/bqb/utils.go:122.26,124.18 2 1
github.com/nullism/bqb/utils.go:127.4,128.44 2 1
github.com/nullism/bqb/utils.go:130.28,132.18 2 1
github.com/nullism/bqb/utils.go:135.4,136.44 2 1
github.com/nullism/bqb/utils.go:138.11,140.32 2 1
github.com/nullism/bqb/utils.go:64.24,67.5 2 1
github.com/nullism/bqb/utils.go:72.24,75.5 2 1
github.com/nullism/bqb/utils.go:76.22,78.5 1 1
github.com/nullism/bqb/utils.go:78.10,81.5 2 1
github.com/nullism/bqb/utils.go:85.24,88.5 2 1
github.com/nullism/bqb/utils.go:93.24,96.5 2 1
github.com/nullism/bqb/utils.go:97.22,99.5 1 1
github.com/nullism/bqb/utils.go:99.10,102.5 2 1
github.com/nullism/bqb/utils.go:106.24,109.5 2 1
github.com/nullism/bqb/utils.go:113.16,116.13 3 1
github.com/nullism/bqb/utils.go:124.18,125.55 1 1
github.com/nullism/bqb/utils.go:132.18,133.55 1 1
github.com/nullism/bqb/utils.go:144.20,145.82 1 1
github.com/nullism/bqb/utils.go:149.31,150.84 1 1
github.com/nullism/bqb/utils.go:161.52,162.27 1 1
github.com/nullism/bqb/utils.go:163.12,164.35 1 1
github.com/nullism/bqb/utils.go:166.33,167.35 1 1
github.com/nullism/bqb/utils.go:168.12,169.15 1 1
github.com/nullism/bqb/utils.go:172.3,172.36 1 1
github.com/nullism/bqb/utils.go:173.14,174.37 1 1
github.com/nullism/bqb/utils.go:175.15,176.15 1 1
github.com/nullism/bqb/utils.go:179.3,179.38 1 1
github.com/nullism/bqb/utils.go:180.11,181.21 1 1
github.com/nullism/bqb/utils.go:182.10,183.65 1 1
github.com/nullism/bqb/utils.go:169.15,171.4 1 1
github.com/nullism/bqb/utils.go:176.15,178.4 1 1
5 changes: 3 additions & 2 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ type JsonMap map[string]interface{}
type JsonList []interface{}

func dialectReplace(dialect Dialect, sql string, params []interface{}) (string, error) {
if dialect == MYSQL || dialect == SQL {
sql = strings.ReplaceAll(sql, paramPh, "?")
}
for i, param := range params {
if dialect == RAW {
p, err := paramToRaw(param)
if err != nil {
return "", err
}
sql = strings.Replace(sql, paramPh, p, 1)
} else if dialect == MYSQL || dialect == SQL {
sql = strings.Replace(sql, paramPh, "?", 1)
} else if dialect == PGSQL {
sql = strings.ReplaceAll(sql, "??", "?")
sql = strings.Replace(sql, paramPh, fmt.Sprintf("$%d", i+1), 1)
Expand Down

0 comments on commit 807385f

Please sign in to comment.