Merge branch 'arjen-ag5/master' into pg_arrays
# Conflicts: # generator/template/model_template.go # generator/template/sql_builder_template.go # internal/jet/expression.go # postgres/cast.go # postgres/columns.go # postgres/expressions.go # postgres/insert_statement_test.go # postgres/literal.go # tests/postgres/alltypes_test.go # tests/postgres/generator_template_test.go # tests/postgres/scan_test.go # tests/postgres/select_test.go
This commit is contained in:
commit
45d4ced9b0
25 changed files with 575 additions and 85 deletions
|
|
@ -93,11 +93,11 @@ func (s *SQLBuilder) write(data []byte) {
|
|||
}
|
||||
|
||||
func isPreSeparator(b byte) bool {
|
||||
return b == ' ' || b == '.' || b == ',' || b == '(' || b == '\n' || b == ':'
|
||||
return b == ' ' || b == '.' || b == ',' || b == '(' || b == '\n' || b == ':' || b == '['
|
||||
}
|
||||
|
||||
func isPostSeparator(b byte) bool {
|
||||
return b == ' ' || b == '.' || b == ',' || b == ')' || b == '\n' || b == ':'
|
||||
return b == ' ' || b == '.' || b == ',' || b == ')' || b == '\n' || b == ':' || b == '[' || b == ']'
|
||||
}
|
||||
|
||||
// WriteAlias is used to add alias to output SQL
|
||||
|
|
@ -249,6 +249,8 @@ func (s *SQLBuilder) argToString(value interface{}) string {
|
|||
|
||||
case string:
|
||||
return stringQuote(bindVal)
|
||||
case []string:
|
||||
return stringArrayQuote(bindVal)
|
||||
case []byte:
|
||||
return stringQuote(string(bindVal))
|
||||
case uuid.UUID:
|
||||
|
|
@ -276,6 +278,19 @@ func (s *SQLBuilder) argToString(value interface{}) string {
|
|||
}
|
||||
}
|
||||
|
||||
func stringArrayQuote(val []string) string {
|
||||
var sb strings.Builder
|
||||
sb.WriteString(`'{`)
|
||||
for i := 0; i < len(val); i++ {
|
||||
if i > 0 {
|
||||
sb.WriteString(`, `)
|
||||
}
|
||||
sb.WriteString(stringDoubleQuote(val[i]))
|
||||
}
|
||||
sb.WriteString(`}'`)
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
func integerTypesToString(value interface{}) string {
|
||||
switch bindVal := value.(type) {
|
||||
case int:
|
||||
|
|
@ -324,3 +339,7 @@ func shouldQuoteIdentifier(identifier string) bool {
|
|||
func stringQuote(value string) string {
|
||||
return `'` + strings.Replace(value, "'", "''", -1) + `'`
|
||||
}
|
||||
|
||||
func stringDoubleQuote(value string) string {
|
||||
return `"` + strings.Replace(value, `"`, `""`, -1) + `"`
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue