Skip to content

Commit

Permalink
Merge branch 'query_builder'
Browse files Browse the repository at this point in the history
  • Loading branch information
abhi-illuminasy committed May 25, 2019
2 parents eeb0366 + 2c6a16c commit 1b9c003
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.1.3 (May 25, 2019)
- Added query builder helper

## 0.1.2 (May 23, 2019)
- Added prepare and transactions

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.2
0.1.3
37 changes: 37 additions & 0 deletions query_builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package gomysql

import (
"fmt"
"strings"
)

// PrepareInsertColumn prepares (?,?,?)
func PrepareInsertColumn(columnCount int) string {
columnStr := `(`
for i := columnCount; i > 0; i-- {
columnStr += `?,`
}

if strings.HasSuffix(columnStr, ",") {
columnStr = columnStr[:len(columnStr)-len(",")]
}

columnStr += `)`

return columnStr
}

// PrepareBatchInsertColumns prepares (?,?,?),(?,?,?),(?,?,?)
func PrepareBatchInsertColumns(rowCount int, columnCount int) string {
rowStr := ""

for i := rowCount; i > 0; i-- {
rowStr += fmt.Sprintf("%s,", PrepareInsertColumn(columnCount))
}

if strings.HasSuffix(rowStr, ",") {
rowStr = rowStr[:len(rowStr)-len(",")]
}

return rowStr
}

0 comments on commit 1b9c003

Please sign in to comment.