@@ -42,6 +42,46 @@ func (d dialect) idType() string {
|
||||
return "INTEGER PRIMARY KEY AUTOINCREMENT"
|
||||
}
|
||||
|
||||
func (d dialect) keyTextType() string {
|
||||
if d.name == "mysql" {
|
||||
return "VARCHAR(191)"
|
||||
}
|
||||
return "TEXT"
|
||||
}
|
||||
|
||||
func (d dialect) shortTextType() string {
|
||||
if d.name == "mysql" {
|
||||
return "VARCHAR(255)"
|
||||
}
|
||||
return "TEXT"
|
||||
}
|
||||
|
||||
func (d dialect) mediumTextType() string {
|
||||
if d.name == "mysql" {
|
||||
return "VARCHAR(1024)"
|
||||
}
|
||||
return "TEXT"
|
||||
}
|
||||
|
||||
func (d dialect) longTextType() string {
|
||||
if d.name == "mysql" {
|
||||
return "LONGTEXT"
|
||||
}
|
||||
return "TEXT"
|
||||
}
|
||||
|
||||
func (d dialect) quoteIdent(identifier string) string {
|
||||
return "`" + strings.ReplaceAll(identifier, "`", "``") + "`"
|
||||
}
|
||||
|
||||
func (d dialect) columnList(columns []string) string {
|
||||
quoted := make([]string, len(columns))
|
||||
for index, column := range columns {
|
||||
quoted[index] = d.quoteIdent(column)
|
||||
}
|
||||
return strings.Join(quoted, ", ")
|
||||
}
|
||||
|
||||
func (d dialect) boolExpr(value bool) int {
|
||||
if value {
|
||||
return 1
|
||||
@@ -54,7 +94,7 @@ func (d dialect) upsert(table string, columns, conflict []string) string {
|
||||
for i := range placeholders {
|
||||
placeholders[i] = "?"
|
||||
}
|
||||
base := fmt.Sprintf("INSERT INTO %s (%s) VALUES (%s)", table, strings.Join(columns, ", "), strings.Join(placeholders, ", "))
|
||||
base := fmt.Sprintf("INSERT INTO %s (%s) VALUES (%s)", table, d.columnList(columns), strings.Join(placeholders, ", "))
|
||||
conflictSet := map[string]bool{}
|
||||
for _, column := range conflict {
|
||||
conflictSet[column] = true
|
||||
@@ -64,10 +104,11 @@ func (d dialect) upsert(table string, columns, conflict []string) string {
|
||||
if conflictSet[column] {
|
||||
continue
|
||||
}
|
||||
quoted := d.quoteIdent(column)
|
||||
if d.name == "mysql" {
|
||||
updates = append(updates, fmt.Sprintf("%s = VALUES(%s)", column, column))
|
||||
updates = append(updates, fmt.Sprintf("%s = VALUES(%s)", quoted, quoted))
|
||||
} else {
|
||||
updates = append(updates, fmt.Sprintf("%s = excluded.%s", column, column))
|
||||
updates = append(updates, fmt.Sprintf("%s = excluded.%s", quoted, quoted))
|
||||
}
|
||||
}
|
||||
if len(updates) == 0 {
|
||||
@@ -79,7 +120,7 @@ func (d dialect) upsert(table string, columns, conflict []string) string {
|
||||
if d.name == "mysql" {
|
||||
return base + " ON DUPLICATE KEY UPDATE " + strings.Join(updates, ", ")
|
||||
}
|
||||
return base + " ON CONFLICT (" + strings.Join(conflict, ", ") + ") DO UPDATE SET " + strings.Join(updates, ", ")
|
||||
return base + " ON CONFLICT (" + d.columnList(conflict) + ") DO UPDATE SET " + strings.Join(updates, ", ")
|
||||
}
|
||||
|
||||
func (d dialect) limitOffset(limit, offset int) string {
|
||||
|
||||
Reference in New Issue
Block a user