voidwalker/model/mysql_upsert.go
Niko Storni 2dc0db7210 add compression for gifs
add database backend
2020-06-16 05:37:51 +02:00

58 lines
1.4 KiB
Go

// Code generated by SQLBoiler 3.7.1 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package model
import (
"fmt"
"strings"
"github.com/volatiletech/sqlboiler/drivers"
"github.com/volatiletech/sqlboiler/strmangle"
)
// buildUpsertQueryMySQL builds a SQL statement string using the upsertData provided.
func buildUpsertQueryMySQL(dia drivers.Dialect, tableName string, update, whitelist []string) string {
whitelist = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, whitelist)
tableName = strmangle.IdentQuote(dia.LQ, dia.RQ, tableName)
buf := strmangle.GetBuffer()
defer strmangle.PutBuffer(buf)
var columns string
if len(whitelist) != 0 {
columns = strings.Join(whitelist, ",")
}
if len(update) == 0 {
fmt.Fprintf(
buf,
"INSERT IGNORE INTO %s (%s) VALUES (%s)",
tableName,
columns,
strmangle.Placeholders(dia.UseIndexPlaceholders, len(whitelist), 1, 1),
)
return buf.String()
}
fmt.Fprintf(
buf,
"INSERT INTO %s (%s) VALUES (%s) ON DUPLICATE KEY UPDATE ",
tableName,
columns,
strmangle.Placeholders(dia.UseIndexPlaceholders, len(whitelist), 1, 1),
)
for i, v := range update {
if i != 0 {
buf.WriteByte(',')
}
quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v)
buf.WriteString(quoted)
buf.WriteString(" = VALUES(")
buf.WriteString(quoted)
buf.WriteByte(')')
}
return buf.String()
}