Add lq, rq, and indexplaceholders args everywhere

This commit is contained in:
Patrick O'brien 2016-09-10 05:15:50 +10:00
parent f14301de7b
commit 793522650c
23 changed files with 160 additions and 92 deletions

View file

@ -1061,6 +1061,10 @@ If your database uses multiple schemas you should generate a new package for eac
Note that this only applies to databases that use real, SQL standard schemas (like PostgreSQL), not Note that this only applies to databases that use real, SQL standard schemas (like PostgreSQL), not
fake schemas (like MySQL). fake schemas (like MySQL).
#### Where is the homepage?
The homepage for the [SQLBoiler](https://github.com/vattle/sqlboiler) [Golang ORM](https://github.com/vattle/sqlboiler) generator is located at: https://github.com/vattle/sqlboiler
## Benchmarks ## Benchmarks
If you'd like to run the benchmarks yourself check out our [boilbench](https://github.com/vattle/boilbench) repo. If you'd like to run the benchmarks yourself check out our [boilbench](https://github.com/vattle/boilbench) repo.

View file

@ -89,12 +89,12 @@ func (p *PostgresDriver) TableNames(schema string, whitelist, blacklist []string
query := fmt.Sprintf(`select table_name from information_schema.tables where table_schema = $1`) query := fmt.Sprintf(`select table_name from information_schema.tables where table_schema = $1`)
args := []interface{}{schema} args := []interface{}{schema}
if len(whitelist) > 0 { if len(whitelist) > 0 {
query += fmt.Sprintf(" and table_name in (%s);", strmangle.Placeholders(len(whitelist), 2, 1)) query += fmt.Sprintf(" and table_name in (%s);", strmangle.Placeholders(true, len(whitelist), 2, 1))
for _, w := range whitelist { for _, w := range whitelist {
args = append(args, w) args = append(args, w)
} }
} else if len(blacklist) > 0 { } else if len(blacklist) > 0 {
query += fmt.Sprintf(" and table_name not in (%s);", strmangle.Placeholders(len(blacklist), 2, 1)) query += fmt.Sprintf(" and table_name not in (%s);", strmangle.Placeholders(true, len(blacklist), 2, 1))
for _, b := range blacklist { for _, b := range blacklist {
args = append(args, b) args = append(args, b)
} }

View file

@ -97,17 +97,17 @@ func (m testMockDriver) PrimaryKeyInfo(schema, tableName string) (*PrimaryKey, e
} }
// RightQuote is the quoting character for the right side of the identifier // RightQuote is the quoting character for the right side of the identifier
func (m *testMockDriver) RightQuote() byte { func (m testMockDriver) RightQuote() byte {
return '"' return '"'
} }
// LeftQuote is the quoting character for the left side of the identifier // LeftQuote is the quoting character for the left side of the identifier
func (m *testMockDriver) LeftQuote() byte { func (m testMockDriver) LeftQuote() byte {
return '"' return '"'
} }
// IndexPlaceholders returns true to indicate fake support of indexed placeholders // IndexPlaceholders returns true to indicate fake support of indexed placeholders
func (m *testMockDriver) IndexPlaceholders() bool { func (m testMockDriver) IndexPlaceholders() bool {
return false return false
} }

View file

@ -57,7 +57,7 @@ func buildSelectQuery(q *Query) (*bytes.Buffer, []interface{}) {
// Don't identQuoteSlice - writeAsStatements does this // Don't identQuoteSlice - writeAsStatements does this
buf.WriteString(strings.Join(selectColsWithAs, ", ")) buf.WriteString(strings.Join(selectColsWithAs, ", "))
} else if hasSelectCols { } else if hasSelectCols {
buf.WriteString(strings.Join(strmangle.IdentQuoteSlice(q.selectCols), ", ")) buf.WriteString(strings.Join(strmangle.IdentQuoteSlice(q.dialect.LQ, q.dialect.RQ, q.selectCols), ", "))
} else if hasJoins { } else if hasJoins {
selectColsWithStars := writeStars(q) selectColsWithStars := writeStars(q)
buf.WriteString(strings.Join(selectColsWithStars, ", ")) buf.WriteString(strings.Join(selectColsWithStars, ", "))
@ -70,7 +70,7 @@ func buildSelectQuery(q *Query) (*bytes.Buffer, []interface{}) {
buf.WriteByte(')') buf.WriteByte(')')
} }
fmt.Fprintf(buf, " FROM %s", strings.Join(strmangle.IdentQuoteSlice(q.from), ", ")) fmt.Fprintf(buf, " FROM %s", strings.Join(strmangle.IdentQuoteSlice(q.dialect.LQ, q.dialect.RQ, q.from), ", "))
if len(q.joins) > 0 { if len(q.joins) > 0 {
argsLen := len(args) argsLen := len(args)
@ -82,7 +82,12 @@ func buildSelectQuery(q *Query) (*bytes.Buffer, []interface{}) {
fmt.Fprintf(joinBuf, " INNER JOIN %s", j.clause) fmt.Fprintf(joinBuf, " INNER JOIN %s", j.clause)
args = append(args, j.args...) args = append(args, j.args...)
} }
resp, _ := convertQuestionMarks(joinBuf.String(), argsLen+1) var resp string
if q.dialect.IndexPlaceholders {
resp, _ = convertQuestionMarks(joinBuf.String(), argsLen+1)
} else {
resp = joinBuf.String()
}
fmt.Fprintf(buf, resp) fmt.Fprintf(buf, resp)
strmangle.PutBuffer(joinBuf) strmangle.PutBuffer(joinBuf)
} }
@ -110,7 +115,7 @@ func buildDeleteQuery(q *Query) (*bytes.Buffer, []interface{}) {
buf := strmangle.GetBuffer() buf := strmangle.GetBuffer()
buf.WriteString("DELETE FROM ") buf.WriteString("DELETE FROM ")
buf.WriteString(strings.Join(strmangle.IdentQuoteSlice(q.from), ", ")) buf.WriteString(strings.Join(strmangle.IdentQuoteSlice(q.dialect.LQ, q.dialect.RQ, q.from), ", "))
where, whereArgs := whereClause(q, 1) where, whereArgs := whereClause(q, 1)
if len(whereArgs) != 0 { if len(whereArgs) != 0 {
@ -135,7 +140,7 @@ func buildUpdateQuery(q *Query) (*bytes.Buffer, []interface{}) {
buf := strmangle.GetBuffer() buf := strmangle.GetBuffer()
buf.WriteString("UPDATE ") buf.WriteString("UPDATE ")
buf.WriteString(strings.Join(strmangle.IdentQuoteSlice(q.from), ", ")) buf.WriteString(strings.Join(strmangle.IdentQuoteSlice(q.dialect.LQ, q.dialect.RQ, q.from), ", "))
cols := make(sort.StringSlice, len(q.update)) cols := make(sort.StringSlice, len(q.update))
var args []interface{} var args []interface{}
@ -150,13 +155,13 @@ func buildUpdateQuery(q *Query) (*bytes.Buffer, []interface{}) {
for i := 0; i < len(cols); i++ { for i := 0; i < len(cols); i++ {
args = append(args, q.update[cols[i]]) args = append(args, q.update[cols[i]])
cols[i] = strmangle.IdentQuote(cols[i]) cols[i] = strmangle.IdentQuote(q.dialect.LQ, q.dialect.RQ, cols[i])
} }
buf.WriteString(fmt.Sprintf( buf.WriteString(fmt.Sprintf(
" SET (%s) = (%s)", " SET (%s) = (%s)",
strings.Join(cols, ", "), strings.Join(cols, ", "),
strmangle.Placeholders(len(cols), 1, 1)), strmangle.Placeholders(q.dialect.IndexPlaceholders, len(cols), 1, 1)),
) )
where, whereArgs := whereClause(q, len(args)+1) where, whereArgs := whereClause(q, len(args)+1)
@ -179,10 +184,10 @@ func buildUpdateQuery(q *Query) (*bytes.Buffer, []interface{}) {
} }
// BuildUpsertQuery builds a SQL statement string using the upsertData provided. // BuildUpsertQuery builds a SQL statement string using the upsertData provided.
func BuildUpsertQuery(tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string) string { func BuildUpsertQuery(dia Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string) string {
conflict = strmangle.IdentQuoteSlice(conflict) conflict = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, conflict)
whitelist = strmangle.IdentQuoteSlice(whitelist) whitelist = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, whitelist)
ret = strmangle.IdentQuoteSlice(ret) ret = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, ret)
buf := strmangle.GetBuffer() buf := strmangle.GetBuffer()
defer strmangle.PutBuffer(buf) defer strmangle.PutBuffer(buf)
@ -192,7 +197,7 @@ func BuildUpsertQuery(tableName string, updateOnConflict bool, ret, update, conf
"INSERT INTO %s (%s) VALUES (%s) ON CONFLICT ", "INSERT INTO %s (%s) VALUES (%s) ON CONFLICT ",
tableName, tableName,
strings.Join(whitelist, ", "), strings.Join(whitelist, ", "),
strmangle.Placeholders(len(whitelist), 1, 1), strmangle.Placeholders(dia.IndexPlaceholders, len(whitelist), 1, 1),
) )
if !updateOnConflict || len(update) == 0 { if !updateOnConflict || len(update) == 0 {
@ -206,7 +211,7 @@ func BuildUpsertQuery(tableName string, updateOnConflict bool, ret, update, conf
if i != 0 { if i != 0 {
buf.WriteByte(',') buf.WriteByte(',')
} }
quoted := strmangle.IdentQuote(v) quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v)
buf.WriteString(quoted) buf.WriteString(quoted)
buf.WriteString(" = EXCLUDED.") buf.WriteString(" = EXCLUDED.")
buf.WriteString(quoted) buf.WriteString(quoted)
@ -237,7 +242,12 @@ func writeModifiers(q *Query, buf *bytes.Buffer, args *[]interface{}) {
fmt.Fprintf(havingBuf, j.clause) fmt.Fprintf(havingBuf, j.clause)
*args = append(*args, j.args...) *args = append(*args, j.args...)
} }
resp, _ := convertQuestionMarks(havingBuf.String(), argsLen+1) var resp string
if q.dialect.IndexPlaceholders {
resp, _ = convertQuestionMarks(havingBuf.String(), argsLen+1)
} else {
resp = havingBuf.String()
}
fmt.Fprintf(buf, resp) fmt.Fprintf(buf, resp)
strmangle.PutBuffer(havingBuf) strmangle.PutBuffer(havingBuf)
} }
@ -264,7 +274,7 @@ func writeStars(q *Query) []string {
for i, f := range q.from { for i, f := range q.from {
toks := strings.Split(f, " ") toks := strings.Split(f, " ")
if len(toks) == 1 { if len(toks) == 1 {
cols[i] = fmt.Sprintf(`%s.*`, strmangle.IdentQuote(toks[0])) cols[i] = fmt.Sprintf(`%s.*`, strmangle.IdentQuote(q.dialect.LQ, q.dialect.RQ, toks[0]))
continue continue
} }
@ -276,7 +286,7 @@ func writeStars(q *Query) []string {
if len(alias) != 0 { if len(alias) != 0 {
name = alias name = alias
} }
cols[i] = fmt.Sprintf(`%s.*`, strmangle.IdentQuote(name)) cols[i] = fmt.Sprintf(`%s.*`, strmangle.IdentQuote(q.dialect.LQ, q.dialect.RQ, name))
} }
return cols return cols
@ -292,7 +302,7 @@ func writeAsStatements(q *Query) []string {
toks := strings.Split(col, ".") toks := strings.Split(col, ".")
if len(toks) == 1 { if len(toks) == 1 {
cols[i] = strmangle.IdentQuote(col) cols[i] = strmangle.IdentQuote(q.dialect.LQ, q.dialect.RQ, col)
continue continue
} }
@ -301,7 +311,7 @@ func writeAsStatements(q *Query) []string {
asParts[j] = strings.Trim(tok, `"`) asParts[j] = strings.Trim(tok, `"`)
} }
cols[i] = fmt.Sprintf(`%s as "%s"`, strmangle.IdentQuote(col), strings.Join(asParts, ".")) cols[i] = fmt.Sprintf(`%s as "%s"`, strmangle.IdentQuote(q.dialect.LQ, q.dialect.RQ, col), strings.Join(asParts, "."))
} }
return cols return cols
@ -335,7 +345,13 @@ func whereClause(q *Query, startAt int) (string, []interface{}) {
args = append(args, where.args...) args = append(args, where.args...)
} }
resp, _ := convertQuestionMarks(buf.String(), startAt) var resp string
if q.dialect.IndexPlaceholders {
resp, _ = convertQuestionMarks(buf.String(), startAt)
} else {
resp = buf.String()
}
return resp, args return resp, args
} }
@ -374,7 +390,7 @@ func inClause(q *Query, startAt int) (string, []interface{}) {
// column name side, however if this case is being hit then the regexp // column name side, however if this case is being hit then the regexp
// probably needs adjustment, or the user is passing in invalid clauses. // probably needs adjustment, or the user is passing in invalid clauses.
if matches == nil { if matches == nil {
clause, count := convertInQuestionMarks(in.clause, startAt, 1, ln) clause, count := convertInQuestionMarks(q.dialect.IndexPlaceholders, in.clause, startAt, 1, ln)
buf.WriteString(clause) buf.WriteString(clause)
startAt = startAt + count startAt = startAt + count
} else { } else {
@ -384,11 +400,24 @@ func inClause(q *Query, startAt int) (string, []interface{}) {
// of the clause to determine how many columns they are using. // of the clause to determine how many columns they are using.
// This number determines the groupAt for the convert function. // This number determines the groupAt for the convert function.
cols := strings.Split(leftSide, ",") cols := strings.Split(leftSide, ",")
cols = strmangle.IdentQuoteSlice(cols) cols = strmangle.IdentQuoteSlice(q.dialect.LQ, q.dialect.RQ, cols)
groupAt := len(cols) groupAt := len(cols)
leftClause, leftCount := convertQuestionMarks(strings.Join(cols, ","), startAt) var leftClause string
rightClause, rightCount := convertInQuestionMarks(rightSide, startAt+leftCount, groupAt, ln-leftCount) var leftCount int
if q.dialect.IndexPlaceholders {
leftClause, leftCount = convertQuestionMarks(strings.Join(cols, ","), startAt)
} else {
// Count the number of cols that are question marks, so we know
// how much to offset convertInQuestionMarks by
for _, v := range cols {
if v == "?" {
leftCount++
}
}
leftClause = strings.Join(cols, ",")
}
rightClause, rightCount := convertInQuestionMarks(q.dialect.IndexPlaceholders, rightSide, startAt+leftCount, groupAt, ln-leftCount)
buf.WriteString(leftClause) buf.WriteString(leftClause)
buf.WriteString(" IN ") buf.WriteString(" IN ")
buf.WriteString(rightClause) buf.WriteString(rightClause)
@ -406,7 +435,7 @@ func inClause(q *Query, startAt int) (string, []interface{}) {
// It uses groupAt to determine how many placeholders should be in each group, // It uses groupAt to determine how many placeholders should be in each group,
// for example, groupAt 2 would result in: (($1,$2),($3,$4)) // for example, groupAt 2 would result in: (($1,$2),($3,$4))
// and groupAt 1 would result in ($1,$2,$3,$4) // and groupAt 1 would result in ($1,$2,$3,$4)
func convertInQuestionMarks(clause string, startAt, groupAt, total int) (string, int) { func convertInQuestionMarks(indexPlaceholders bool, clause string, startAt, groupAt, total int) (string, int) {
if startAt == 0 || len(clause) == 0 { if startAt == 0 || len(clause) == 0 {
panic("Not a valid start number.") panic("Not a valid start number.")
} }
@ -428,7 +457,7 @@ func convertInQuestionMarks(clause string, startAt, groupAt, total int) (string,
paramBuf.WriteString(clause[:foundAt]) paramBuf.WriteString(clause[:foundAt])
paramBuf.WriteByte('(') paramBuf.WriteByte('(')
paramBuf.WriteString(strmangle.Placeholders(total, startAt, groupAt)) paramBuf.WriteString(strmangle.Placeholders(indexPlaceholders, total, startAt, groupAt))
paramBuf.WriteByte(')') paramBuf.WriteByte(')')
paramBuf.WriteString(clause[foundAt+1:]) paramBuf.WriteString(clause[foundAt+1:])

View file

@ -97,6 +97,7 @@ func TestBuildQuery(t *testing.T) {
for i, test := range tests { for i, test := range tests {
filename := filepath.Join("_fixtures", fmt.Sprintf("%02d.sql", i)) filename := filepath.Join("_fixtures", fmt.Sprintf("%02d.sql", i))
test.q.dialect = &Dialect{LQ: '"', RQ: '"', IndexPlaceholders: true}
out, args := buildQuery(test.q) out, args := buildQuery(test.q)
if *writeGoldenFiles { if *writeGoldenFiles {
@ -149,6 +150,7 @@ func TestWriteStars(t *testing.T) {
} }
for i, test := range tests { for i, test := range tests {
test.In.dialect = &Dialect{LQ: '"', RQ: '"', IndexPlaceholders: true}
selects := writeStars(&test.In) selects := writeStars(&test.In)
if !reflect.DeepEqual(selects, test.Out) { if !reflect.DeepEqual(selects, test.Out) {
t.Errorf("writeStar test fail %d\nwant: %v\ngot: %v", i, test.Out, selects) t.Errorf("writeStar test fail %d\nwant: %v\ngot: %v", i, test.Out, selects)
@ -275,6 +277,7 @@ func TestWhereClause(t *testing.T) {
} }
for i, test := range tests { for i, test := range tests {
test.q.dialect = &Dialect{LQ: '"', RQ: '"', IndexPlaceholders: true}
result, _ := whereClause(&test.q, 1) result, _ := whereClause(&test.q, 1)
if result != test.expect { if result != test.expect {
t.Errorf("%d) Mismatch between expect and result:\n%s\n%s\n", i, test.expect, result) t.Errorf("%d) Mismatch between expect and result:\n%s\n%s\n", i, test.expect, result)
@ -407,6 +410,7 @@ func TestInClause(t *testing.T) {
} }
for i, test := range tests { for i, test := range tests {
test.q.dialect = &Dialect{LQ: '"', RQ: '"', IndexPlaceholders: true}
result, args := inClause(&test.q, 1) result, args := inClause(&test.q, 1)
if result != test.expect { if result != test.expect {
t.Errorf("%d) Mismatch between expect and result:\n%s\n%s\n", i, test.expect, result) t.Errorf("%d) Mismatch between expect and result:\n%s\n%s\n", i, test.expect, result)
@ -489,7 +493,7 @@ func TestConvertInQuestionMarks(t *testing.T) {
} }
for i, test := range tests { for i, test := range tests {
res, count := convertInQuestionMarks(test.clause, test.start, test.group, test.total) res, count := convertInQuestionMarks(true, test.clause, test.start, test.group, test.total)
if res != test.expect { if res != test.expect {
t.Errorf("%d) Mismatch between expect and result:\n%s\n%s\n", i, test.expect, res) t.Errorf("%d) Mismatch between expect and result:\n%s\n%s\n", i, test.expect, res)
} }
@ -497,6 +501,14 @@ func TestConvertInQuestionMarks(t *testing.T) {
t.Errorf("%d) Expected %d, got %d", i, test.total, count) t.Errorf("%d) Expected %d, got %d", i, test.total, count)
} }
} }
res, count := convertInQuestionMarks(false, "?", 1, 3, 9)
if res != "((?,?,?),(?,?,?),(?,?,?))" {
t.Errorf("Mismatch between expected and result: %s", res)
}
if count != 9 {
t.Errorf("Expected 9 results, got %d", count)
}
} }
func TestWriteAsStatements(t *testing.T) { func TestWriteAsStatements(t *testing.T) {
@ -512,6 +524,7 @@ func TestWriteAsStatements(t *testing.T) {
`a.clown.run`, `a.clown.run`,
`COUNT(a)`, `COUNT(a)`,
}, },
dialect: &Dialect{LQ: '"', RQ: '"', IndexPlaceholders: true},
} }
expect := []string{ expect := []string{

View file

@ -44,7 +44,8 @@ func TestBindStruct(t *testing.T) {
}{} }{}
query := &Query{ query := &Query{
from: []string{"fun"}, from: []string{"fun"},
dialect: &Dialect{LQ: '"', RQ: '"', IndexPlaceholders: true},
} }
db, mock, err := sqlmock.New() db, mock, err := sqlmock.New()
@ -83,7 +84,8 @@ func TestBindSlice(t *testing.T) {
}{} }{}
query := &Query{ query := &Query{
from: []string{"fun"}, from: []string{"fun"},
dialect: &Dialect{LQ: '"', RQ: '"', IndexPlaceholders: true},
} }
db, mock, err := sqlmock.New() db, mock, err := sqlmock.New()
@ -133,7 +135,8 @@ func TestBindPtrSlice(t *testing.T) {
}{} }{}
query := &Query{ query := &Query{
from: []string{"fun"}, from: []string{"fun"},
dialect: &Dialect{LQ: '"', RQ: '"', IndexPlaceholders: true},
} }
db, mock, err := sqlmock.New() db, mock, err := sqlmock.New()
@ -369,7 +372,8 @@ func TestBindSingular(t *testing.T) {
}{} }{}
query := &Query{ query := &Query{
from: []string{"fun"}, from: []string{"fun"},
dialect: &Dialect{LQ: '"', RQ: '"', IndexPlaceholders: true},
} }
db, mock, err := sqlmock.New() db, mock, err := sqlmock.New()
@ -412,8 +416,9 @@ func TestBind_InnerJoin(t *testing.T) {
}{} }{}
query := &Query{ query := &Query{
from: []string{"fun"}, from: []string{"fun"},
joins: []join{{kind: JoinInner, clause: "happy as h on fun.id = h.fun_id"}}, joins: []join{{kind: JoinInner, clause: "happy as h on fun.id = h.fun_id"}},
dialect: &Dialect{LQ: '"', RQ: '"', IndexPlaceholders: true},
} }
db, mock, err := sqlmock.New() db, mock, err := sqlmock.New()

View file

@ -38,17 +38,17 @@ func init() {
// using a database that supports real schemas, for example, // using a database that supports real schemas, for example,
// for Postgres: "schema_name"."table_name", versus // for Postgres: "schema_name"."table_name", versus
// simply "table_name" for MySQL (because it does not support real schemas) // simply "table_name" for MySQL (because it does not support real schemas)
func SchemaTable(driver string, schema string, table string) string { func SchemaTable(lq byte, rq byte, driver string, schema string, table string) string {
if driver == "postgres" && schema != "public" { if driver == "postgres" && schema != "public" {
return fmt.Sprintf(`"%s"."%s"`, schema, table) return fmt.Sprintf(`%c%s%c.%c%s%c`, lq, schema, rq, lq, table, rq)
} }
return fmt.Sprintf(`"%s"`, table) return fmt.Sprintf(`%c%s%c`, lq, table, rq)
} }
// IdentQuote attempts to quote simple identifiers in SQL tatements // IdentQuote attempts to quote simple identifiers in SQL tatements
func IdentQuote(lq byte, rq byte, s string) string { func IdentQuote(lq byte, rq byte, s string) string {
if strings.ToLower(s) == "null" { if strings.ToLower(s) == "null" || s == "?" {
return s return s
} }
@ -65,14 +65,14 @@ func IdentQuote(lq byte, rq byte, s string) string {
buf.WriteByte('.') buf.WriteByte('.')
} }
if strings.HasPrefix(split, `"`) || strings.HasSuffix(split, `"`) || split == "*" { if split[0] == lq || split[len(split)-1] == rq || split == "*" {
buf.WriteString(split) buf.WriteString(split)
continue continue
} }
buf.WriteByte('"') buf.WriteByte(lq)
buf.WriteString(split) buf.WriteString(split)
buf.WriteByte('"') buf.WriteByte(rq)
} }
return buf.String() return buf.String()
@ -86,7 +86,7 @@ func IdentQuoteSlice(lq byte, rq byte, s []string) []string {
strs := make([]string, len(s)) strs := make([]string, len(s))
for i, str := range s { for i, str := range s {
strs[i] = IdentQuote(str) strs[i] = IdentQuote(lq, rq, str)
} }
return strs return strs
@ -381,7 +381,8 @@ func PrefixStringSlice(str string, strs []string) []string {
// Placeholders generates the SQL statement placeholders for in queries. // Placeholders generates the SQL statement placeholders for in queries.
// For example, ($1,$2,$3),($4,$5,$6) etc. // For example, ($1,$2,$3),($4,$5,$6) etc.
// It will start counting placeholders at "start". // It will start counting placeholders at "start".
func Placeholders(count int, start int, group int) string { // If indexPlaceholders is false, it will convert to ? instead of $1 etc.
func Placeholders(indexPlaceholders bool, count int, start int, group int) string {
buf := GetBuffer() buf := GetBuffer()
defer PutBuffer(buf) defer PutBuffer(buf)
@ -400,7 +401,11 @@ func Placeholders(count int, start int, group int) string {
buf.WriteByte(',') buf.WriteByte(',')
} }
} }
buf.WriteString(fmt.Sprintf("$%d", start+i)) if indexPlaceholders {
buf.WriteString(fmt.Sprintf("$%d", start+i))
} else {
buf.WriteByte('?')
}
} }
if group > 1 { if group > 1 {
buf.WriteByte(')') buf.WriteByte(')')

View file

@ -29,7 +29,7 @@ func TestIdentQuote(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
if got := IdentQuote(test.In); got != test.Out { if got := IdentQuote('"', '"', test.In); got != test.Out {
t.Errorf("want: %s, got: %s", test.Out, got) t.Errorf("want: %s, got: %s", test.Out, got)
} }
} }
@ -38,7 +38,7 @@ func TestIdentQuote(t *testing.T) {
func TestIdentQuoteSlice(t *testing.T) { func TestIdentQuoteSlice(t *testing.T) {
t.Parallel() t.Parallel()
ret := IdentQuoteSlice([]string{`thing`, `null`}) ret := IdentQuoteSlice('"', '"', []string{`thing`, `null`})
if ret[0] != `"thing"` { if ret[0] != `"thing"` {
t.Error(ret[0]) t.Error(ret[0])
} }
@ -72,31 +72,43 @@ func TestIdentifier(t *testing.T) {
func TestPlaceholders(t *testing.T) { func TestPlaceholders(t *testing.T) {
t.Parallel() t.Parallel()
x := Placeholders(1, 2, 1) x := Placeholders(true, 1, 2, 1)
want := "$2" want := "$2"
if want != x { if want != x {
t.Errorf("want %s, got %s", want, x) t.Errorf("want %s, got %s", want, x)
} }
x = Placeholders(5, 1, 1) x = Placeholders(true, 5, 1, 1)
want = "$1,$2,$3,$4,$5" want = "$1,$2,$3,$4,$5"
if want != x { if want != x {
t.Errorf("want %s, got %s", want, x) t.Errorf("want %s, got %s", want, x)
} }
x = Placeholders(6, 1, 2) x = Placeholders(false, 5, 1, 1)
want = "?,?,?,?,?"
if want != x {
t.Errorf("want %s, got %s", want, x)
}
x = Placeholders(true, 6, 1, 2)
want = "($1,$2),($3,$4),($5,$6)" want = "($1,$2),($3,$4),($5,$6)"
if want != x { if want != x {
t.Errorf("want %s, got %s", want, x) t.Errorf("want %s, got %s", want, x)
} }
x = Placeholders(9, 1, 3) x = Placeholders(true, 6, 1, 2)
want = "($1,$2,$3),($4,$5,$6),($7,$8,$9)" want = "($1,$2),($3,$4),($5,$6)"
if want != x { if want != x {
t.Errorf("want %s, got %s", want, x) t.Errorf("want %s, got %s", want, x)
} }
x = Placeholders(7, 1, 3) x = Placeholders(false, 9, 1, 3)
want = "(?,?,?),(?,?,?),(?,?,?)"
if want != x {
t.Errorf("want %s, got %s", want, x)
}
x = Placeholders(true, 7, 1, 3)
want = "($1,$2,$3),($4,$5,$6),($7)" want = "($1,$2,$3),($4,$5,$6),($7)"
if want != x { if want != x {
t.Errorf("want %s, got %s", want, x) t.Errorf("want %s, got %s", want, x)

View file

@ -16,7 +16,7 @@ func ({{.Function.Receiver}} *{{.LocalTable.NameGo}}) {{.Function.Name}}(exec bo
queryMods = append(queryMods, mods...) queryMods = append(queryMods, mods...)
query := {{.ForeignTable.NamePluralGo}}(exec, queryMods...) query := {{.ForeignTable.NamePluralGo}}(exec, queryMods...)
boil.SetFrom(query.Query, `{{schemaTable $tmplData.DriverName $tmplData.Schema .ForeignTable.Name}}`) boil.SetFrom(query.Query, `{{schemaTable $tmplData.Dialect.LQ $tmplData.Dialect.RQ $tmplData.DriverName $tmplData.Schema .ForeignTable.Name}}`)
return query return query
} }

View file

@ -31,7 +31,7 @@ func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) {{$rel.Function.Na
{{if .ToJoinTable -}} {{if .ToJoinTable -}}
queryMods = append(queryMods, queryMods = append(queryMods,
qm.InnerJoin(`{{schemaTable $dot.DriverName $dot.Schema .JoinTable}} as "{{id 1}}" on "{{id 0}}"."{{.ForeignColumn}}" = "{{id 1}}"."{{.JoinForeignColumn}}"`), qm.InnerJoin(`{{schemaTable $dot.Dialect.LQ $dot.Dialect.RQ $dot.DriverName $dot.Schema .JoinTable}} as "{{id 1}}" on "{{id 0}}"."{{.ForeignColumn}}" = "{{id 1}}"."{{.JoinForeignColumn}}"`),
qm.Where(`"{{id 1}}"."{{.JoinLocalColumn}}"=$1`, {{$rel.Function.Receiver}}.{{$rel.LocalTable.ColumnNameGo}}), qm.Where(`"{{id 1}}"."{{.JoinLocalColumn}}"=$1`, {{$rel.Function.Receiver}}.{{$rel.LocalTable.ColumnNameGo}}),
) )
{{else -}} {{else -}}
@ -41,7 +41,7 @@ func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) {{$rel.Function.Na
{{end}} {{end}}
query := {{$rel.ForeignTable.NamePluralGo}}(exec, queryMods...) query := {{$rel.ForeignTable.NamePluralGo}}(exec, queryMods...)
boil.SetFrom(query.Query, `{{schemaTable $dot.DriverName $dot.Schema .ForeignTable}} as "{{id 0}}"`) boil.SetFrom(query.Query, `{{schemaTable $dot.Dialect.LQ $dot.Dialect.RQ $dot.DriverName $dot.Schema .ForeignTable}} as "{{id 0}}"`)
return query return query
} }

View file

@ -28,8 +28,8 @@ func ({{$varNameSingular}}L) Load{{.Function.Name}}(e boil.Executor, singular bo
} }
query := fmt.Sprintf( query := fmt.Sprintf(
`select * from {{schemaTable $tmplData.DriverName $tmplData.Schema .ForeignKey.ForeignTable}} where "{{.ForeignKey.ForeignColumn}}" in (%s)`, `select * from {{schemaTable $tmplData.Dialect.LQ $tmplData.Dialect.RQ $tmplData.DriverName $tmplData.Schema .ForeignKey.ForeignTable}} where "{{.ForeignKey.ForeignColumn}}" in (%s)`,
strmangle.Placeholders(count, 1, 1), strmangle.Placeholders(dialect.IndexPlaceholders, count, 1, 1),
) )
if boil.DebugMode { if boil.DebugMode {

View file

@ -38,13 +38,13 @@ func ({{$varNameSingular}}L) Load{{$txt.Function.Name}}(e boil.Executor, singula
{{if .ToJoinTable -}} {{if .ToJoinTable -}}
query := fmt.Sprintf( query := fmt.Sprintf(
`select "{{id 0}}".*, "{{id 1}}"."{{.JoinLocalColumn}}" from {{schemaTable $dot.DriverName $dot.Schema .ForeignTable}} as "{{id 0}}" inner join {{schemaTable $dot.DriverName $dot.Schema .JoinTable}} as "{{id 1}}" on "{{id 0}}"."{{.ForeignColumn}}" = "{{id 1}}"."{{.JoinForeignColumn}}" where "{{id 1}}"."{{.JoinLocalColumn}}" in (%s)`, `select "{{id 0}}".*, "{{id 1}}"."{{.JoinLocalColumn}}" from {{schemaTable $dot.Dialect.LQ $dot.Dialect.RQ $dot.DriverName $dot.Schema .ForeignTable}} as "{{id 0}}" inner join {{schemaTable $dot.Dialect.LQ $dot.Dialect.RQ $dot.DriverName $dot.Schema .JoinTable}} as "{{id 1}}" on "{{id 0}}"."{{.ForeignColumn}}" = "{{id 1}}"."{{.JoinForeignColumn}}" where "{{id 1}}"."{{.JoinLocalColumn}}" in (%s)`,
strmangle.Placeholders(count, 1, 1), strmangle.Placeholders(dialect.IndexPlaceholders, count, 1, 1),
) )
{{else -}} {{else -}}
query := fmt.Sprintf( query := fmt.Sprintf(
`select * from {{schemaTable $dot.DriverName $dot.Schema .ForeignTable}} where "{{.ForeignColumn}}" in (%s)`, `select * from {{schemaTable $dot.Dialect.LQ $dot.Dialect.RQ $dot.DriverName $dot.Schema .ForeignTable}} where "{{.ForeignColumn}}" in (%s)`,
strmangle.Placeholders(count, 1, 1), strmangle.Placeholders(dialect.IndexPlaceholders, count, 1, 1),
) )
{{end -}} {{end -}}

View file

@ -39,7 +39,7 @@ func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) Add{{$rel.Function
{{if .ToJoinTable -}} {{if .ToJoinTable -}}
for _, rel := range related { for _, rel := range related {
query := `insert into {{schemaTable $dot.DriverName $dot.Schema .JoinTable}} ({{.JoinLocalColumn}}, {{.JoinForeignColumn}}) values ($1, $2)` query := `insert into {{schemaTable $dot.Dialect.LQ $dot.Dialect.RQ $dot.DriverName $dot.Schema .JoinTable}} ({{.JoinLocalColumn}}, {{.JoinForeignColumn}}) values ($1, $2)`
values := []interface{}{{"{"}}{{$rel.Function.Receiver}}.{{$rel.LocalTable.ColumnNameGo}}, rel.{{$rel.ForeignTable.ColumnNameGo}}} values := []interface{}{{"{"}}{{$rel.Function.Receiver}}.{{$rel.LocalTable.ColumnNameGo}}, rel.{{$rel.ForeignTable.ColumnNameGo}}}
if boil.DebugMode { if boil.DebugMode {
@ -96,10 +96,10 @@ func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) Add{{$rel.Function
// Sets related.R.{{$rel.Function.ForeignName}}'s {{$rel.Function.Name}} accordingly. // Sets related.R.{{$rel.Function.ForeignName}}'s {{$rel.Function.Name}} accordingly.
func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) Set{{$rel.Function.Name}}(exec boil.Executor, insert bool, related ...*{{$rel.ForeignTable.NameGo}}) error { func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) Set{{$rel.Function.Name}}(exec boil.Executor, insert bool, related ...*{{$rel.ForeignTable.NameGo}}) error {
{{if .ToJoinTable -}} {{if .ToJoinTable -}}
query := `delete from {{schemaTable $dot.DriverName $dot.Schema .JoinTable}} where "{{.JoinLocalColumn}}" = $1` query := `delete from {{schemaTable $dot.Dialect.LQ $dot.Dialect.RQ $dot.DriverName $dot.Schema .JoinTable}} where "{{.JoinLocalColumn}}" = $1`
values := []interface{}{{"{"}}{{$rel.Function.Receiver}}.{{$rel.LocalTable.ColumnNameGo}}} values := []interface{}{{"{"}}{{$rel.Function.Receiver}}.{{$rel.LocalTable.ColumnNameGo}}}
{{else -}} {{else -}}
query := `update {{schemaTable $dot.DriverName $dot.Schema .ForeignTable}} set "{{.ForeignColumn}}" = null where "{{.ForeignColumn}}" = $1` query := `update {{schemaTable $dot.Dialect.LQ $dot.Dialect.RQ $dot.DriverName $dot.Schema .ForeignTable}} set "{{.ForeignColumn}}" = null where "{{.ForeignColumn}}" = $1`
values := []interface{}{{"{"}}{{$rel.Function.Receiver}}.{{$rel.LocalTable.ColumnNameGo}}} values := []interface{}{{"{"}}{{$rel.Function.Receiver}}.{{$rel.LocalTable.ColumnNameGo}}}
{{end -}} {{end -}}
if boil.DebugMode { if boil.DebugMode {
@ -140,8 +140,8 @@ func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) Remove{{$rel.Funct
var err error var err error
{{if .ToJoinTable -}} {{if .ToJoinTable -}}
query := fmt.Sprintf( query := fmt.Sprintf(
`delete from {{schemaTable $dot.DriverName $dot.Schema .JoinTable}} where "{{.JoinLocalColumn}}" = $1 and "{{.JoinForeignColumn}}" in (%s)`, `delete from {{schemaTable $dot.Dialect.LQ $dot.Dialect.RQ $dot.DriverName $dot.Schema .JoinTable}} where "{{.JoinLocalColumn}}" = $1 and "{{.JoinForeignColumn}}" in (%s)`,
strmangle.Placeholders(len(related), 1, 1), strmangle.Placeholders(dialect.IndexPlaceholders, len(related), 1, 1),
) )
values := []interface{}{{"{"}}{{$rel.Function.Receiver}}.{{$rel.LocalTable.ColumnNameGo}}} values := []interface{}{{"{"}}{{$rel.Function.Receiver}}.{{$rel.LocalTable.ColumnNameGo}}}

View file

@ -8,6 +8,6 @@ func {{$tableNamePlural}}G(mods ...qm.QueryMod) {{$varNameSingular}}Query {
// {{$tableNamePlural}} retrieves all the records using an executor. // {{$tableNamePlural}} retrieves all the records using an executor.
func {{$tableNamePlural}}(exec boil.Executor, mods ...qm.QueryMod) {{$varNameSingular}}Query { func {{$tableNamePlural}}(exec boil.Executor, mods ...qm.QueryMod) {{$varNameSingular}}Query {
mods = append(mods, qm.From(`{{schemaTable .DriverName .Schema .Table.Name}}`)) mods = append(mods, qm.From(`{{schemaTable .Dialect.LQ .Dialect.RQ .DriverName .Schema .Table.Name}}`))
return {{$varNameSingular}}Query{NewQuery(exec, mods...)} return {{$varNameSingular}}Query{NewQuery(exec, mods...)}
} }

View file

@ -26,10 +26,10 @@ func Find{{$tableNameSingular}}(exec boil.Executor, {{$pkArgs}}, selectCols ...s
sel := "*" sel := "*"
if len(selectCols) > 0 { if len(selectCols) > 0 {
sel = strings.Join(strmangle.IdentQuoteSlice(selectCols), ",") sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
} }
query := fmt.Sprintf( query := fmt.Sprintf(
`select %s from {{schemaTable .DriverName .Schema .Table.Name}} where {{whereClause 1 .Table.PKey.Columns}}`, sel, `select %s from {{schemaTable .Dialect.LQ .Dialect.RQ .DriverName .Schema .Table.Name}} where {{whereClause 1 .Table.PKey.Columns}}`, sel,
) )
q := boil.SQL(exec, query, {{$pkNames | join ", "}}) q := boil.SQL(exec, query, {{$pkNames | join ", "}})

View file

@ -64,11 +64,11 @@ func (o *{{$tableNameSingular}}) Insert(exec boil.Executor, whitelist ... string
if err != nil { if err != nil {
return err return err
} }
cache.query = fmt.Sprintf(`INSERT INTO {{schemaTable .DriverName .Schema .Table.Name}} ("%s") VALUES (%s)`, strings.Join(wl, `","`), strmangle.Placeholders(len(wl), 1, 1)) cache.query = fmt.Sprintf(`INSERT INTO {{schemaTable .Dialect.LQ .Dialect.RQ .DriverName .Schema .Table.Name}} ("%s") VALUES (%s)`, strings.Join(wl, `","`), strmangle.Placeholders(dialect.IndexPlaceholders, len(wl), 1, 1))
if len(cache.retMapping) != 0 { if len(cache.retMapping) != 0 {
{{if .UseLastInsertID -}} {{if .UseLastInsertID -}}
cache.retQuery = fmt.Sprintf(`SELECT %s FROM {{schemaTable .DriverName .Schema .Table.Name}} WHERE %s`, strings.Join(returnColumns, `","`), strmangle.WhereClause(1, {{$varNameSingular}}PrimaryKeyColumns)) cache.retQuery = fmt.Sprintf(`SELECT %s FROM {{schemaTable .Dialect.LQ .Dialect.RQ .DriverName .Schema .Table.Name}} WHERE %s`, strings.Join(returnColumns, `","`), strmangle.WhereClause(1, {{$varNameSingular}}PrimaryKeyColumns))
{{else -}} {{else -}}
cache.query += fmt.Sprintf(` RETURNING %s`, strings.Join(returnColumns, ",")) cache.query += fmt.Sprintf(` RETURNING %s`, strings.Join(returnColumns, ","))
{{end -}} {{end -}}

View file

@ -52,7 +52,7 @@ func (o *{{$tableNameSingular}}) Update(exec boil.Executor, whitelist ... string
if !cached { if !cached {
wl := strmangle.UpdateColumnSet({{$varNameSingular}}Columns, {{$varNameSingular}}PrimaryKeyColumns, whitelist) wl := strmangle.UpdateColumnSet({{$varNameSingular}}Columns, {{$varNameSingular}}PrimaryKeyColumns, whitelist)
cache.query = fmt.Sprintf(`UPDATE {{schemaTable .DriverName .Schema .Table.Name}} SET %s WHERE %s`, strmangle.SetParamNames(wl), strmangle.WhereClause(len(wl)+1, {{$varNameSingular}}PrimaryKeyColumns)) cache.query = fmt.Sprintf(`UPDATE {{schemaTable .Dialect.LQ .Dialect.RQ .DriverName .Schema .Table.Name}} SET %s WHERE %s`, strmangle.SetParamNames(wl), strmangle.WhereClause(len(wl)+1, {{$varNameSingular}}PrimaryKeyColumns))
cache.valueMapping, err = boil.BindMapping({{$varNameSingular}}Type, {{$varNameSingular}}Mapping, append(wl, {{$varNameSingular}}PrimaryKeyColumns...)) cache.valueMapping, err = boil.BindMapping({{$varNameSingular}}Type, {{$varNameSingular}}Mapping, append(wl, {{$varNameSingular}}PrimaryKeyColumns...))
if err != nil { if err != nil {
return err return err
@ -146,7 +146,7 @@ func (o {{$tableNameSingular}}Slice) UpdateAll(exec boil.Executor, cols M) error
i := 0 i := 0
for name, value := range cols { for name, value := range cols {
colNames[i] = strmangle.IdentQuote(name) colNames[i] = strmangle.IdentQuote(dialect.LQ, dialect.RQ, name)
args[i] = value args[i] = value
i++ i++
} }
@ -155,11 +155,11 @@ func (o {{$tableNameSingular}}Slice) UpdateAll(exec boil.Executor, cols M) error
args = append(args, o.inPrimaryKeyArgs()...) args = append(args, o.inPrimaryKeyArgs()...)
sql := fmt.Sprintf( sql := fmt.Sprintf(
`UPDATE {{schemaTable .DriverName .Schema .Table.Name}} SET (%s) = (%s) WHERE (%s) IN (%s)`, `UPDATE {{schemaTable .Dialect.LQ .Dialect.RQ .DriverName .Schema .Table.Name}} SET (%s) = (%s) WHERE (%s) IN (%s)`,
strings.Join(colNames, ", "), strings.Join(colNames, ", "),
strmangle.Placeholders(len(colNames), 1, 1), strmangle.Placeholders(dialect.IndexPlaceholders, len(colNames), 1, 1),
strings.Join(strmangle.IdentQuoteSlice({{$varNameSingular}}PrimaryKeyColumns), ","), strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, {{$varNameSingular}}PrimaryKeyColumns), ","),
strmangle.Placeholders(len(o) * len({{$varNameSingular}}PrimaryKeyColumns), len(colNames)+1, len({{$varNameSingular}}PrimaryKeyColumns)), strmangle.Placeholders(dialect.IndexPlaceholders, len(o) * len({{$varNameSingular}}PrimaryKeyColumns), len(colNames)+1, len({{$varNameSingular}}PrimaryKeyColumns)),
) )
if boil.DebugMode { if boil.DebugMode {

View file

@ -54,7 +54,7 @@ func (o *{{$tableNameSingular}}) Upsert(exec boil.Executor, updateOnConflict boo
copy(conflict, {{$varNameSingular}}PrimaryKeyColumns) copy(conflict, {{$varNameSingular}}PrimaryKeyColumns)
} }
query := boil.BuildUpsertQuery("{{.Table.Name}}", updateOnConflict, ret, update, conflict, whitelist) query := boil.BuildUpsertQuery(dialect, "{{.Table.Name}}", updateOnConflict, ret, update, conflict, whitelist)
if boil.DebugMode { if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, query) fmt.Fprintln(boil.DebugWriter, query)

View file

@ -43,7 +43,7 @@ func (o *{{$tableNameSingular}}) Delete(exec boil.Executor) error {
args := o.inPrimaryKeyArgs() args := o.inPrimaryKeyArgs()
sql := `DELETE FROM {{schemaTable .DriverName .Schema .Table.Name}} WHERE {{whereClause 1 .Table.PKey.Columns}}` sql := `DELETE FROM {{schemaTable .Dialect.LQ .Dialect.RQ .DriverName .Schema .Table.Name}} WHERE {{whereClause 1 .Table.PKey.Columns}}`
if boil.DebugMode { if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, sql) fmt.Fprintln(boil.DebugWriter, sql)
@ -132,9 +132,9 @@ func (o {{$tableNameSingular}}Slice) DeleteAll(exec boil.Executor) error {
args := o.inPrimaryKeyArgs() args := o.inPrimaryKeyArgs()
sql := fmt.Sprintf( sql := fmt.Sprintf(
`DELETE FROM {{schemaTable .DriverName .Schema .Table.Name}} WHERE (%s) IN (%s)`, `DELETE FROM {{schemaTable .Dialect.LQ .Dialect.RQ .DriverName .Schema .Table.Name}} WHERE (%s) IN (%s)`,
strings.Join(strmangle.IdentQuoteSlice({{$varNameSingular}}PrimaryKeyColumns), ","), strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, {{$varNameSingular}}PrimaryKeyColumns), ","),
strmangle.Placeholders(len(o) * len({{$varNameSingular}}PrimaryKeyColumns), 1, len({{$varNameSingular}}PrimaryKeyColumns)), strmangle.Placeholders(dialect.IndexPlaceholders, len(o) * len({{$varNameSingular}}PrimaryKeyColumns), 1, len({{$varNameSingular}}PrimaryKeyColumns)),
) )
if boil.DebugMode { if boil.DebugMode {

View file

@ -67,9 +67,9 @@ func (o *{{$tableNameSingular}}Slice) ReloadAll(exec boil.Executor) error {
args := o.inPrimaryKeyArgs() args := o.inPrimaryKeyArgs()
sql := fmt.Sprintf( sql := fmt.Sprintf(
`SELECT {{schemaTable .DriverName .Schema .Table.Name}}.* FROM {{schemaTable .DriverName .Schema .Table.Name}} WHERE (%s) IN (%s)`, `SELECT {{schemaTable .Dialect.LQ .Dialect.RQ .DriverName .Schema .Table.Name}}.* FROM {{schemaTable .Dialect.LQ .Dialect.RQ .DriverName .Schema .Table.Name}} WHERE (%s) IN (%s)`,
strings.Join(strmangle.IdentQuoteSlice({{$varNameSingular}}PrimaryKeyColumns), ","), strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, {{$varNameSingular}}PrimaryKeyColumns), ","),
strmangle.Placeholders(len(*o) * len({{$varNameSingular}}PrimaryKeyColumns), 1, len({{$varNameSingular}}PrimaryKeyColumns)), strmangle.Placeholders(dialect.IndexPlaceholders, len(*o) * len({{$varNameSingular}}PrimaryKeyColumns), 1, len({{$varNameSingular}}PrimaryKeyColumns)),
) )
q := boil.SQL(exec, sql, args...) q := boil.SQL(exec, sql, args...)

View file

@ -6,7 +6,7 @@
func {{$tableNameSingular}}Exists(exec boil.Executor, {{$pkArgs}}) (bool, error) { func {{$tableNameSingular}}Exists(exec boil.Executor, {{$pkArgs}}) (bool, error) {
var exists bool var exists bool
sql := `select exists(select 1 from {{schemaTable .DriverName .Schema .Table.Name}} where {{whereClause 1 .Table.PKey.Columns}} limit 1)` sql := `select exists(select 1 from {{schemaTable .Dialect.LQ .Dialect.RQ .DriverName .Schema .Table.Name}} where {{whereClause 1 .Table.PKey.Columns}} limit 1)`
if boil.DebugMode { if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, sql) fmt.Fprintln(boil.DebugWriter, sql)

View file

@ -1,4 +1,4 @@
var dialect boil.Dialect = boil.Dialect{ var dialect = boil.Dialect{
LQ: 0x{{printf "%x" .Dialect.LQ}}, LQ: 0x{{printf "%x" .Dialect.LQ}},
RQ: 0x{{printf "%x" .Dialect.RQ}}, RQ: 0x{{printf "%x" .Dialect.RQ}},
IndexPlaceholders: {{.Dialect.IndexPlaceholders}}, IndexPlaceholders: {{.Dialect.IndexPlaceholders}},

View file

@ -41,11 +41,11 @@ func test{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}}(t *testing.T) {
} }
{{if .ToJoinTable -}} {{if .ToJoinTable -}}
_, err = tx.Exec(`insert into {{schemaTable $dot.DriverName $dot.Schema .JoinTable}} ({{.JoinLocalColumn}}, {{.JoinForeignColumn}}) values ($1, $2)`, a.{{$rel.LocalTable.ColumnNameGo}}, b.{{$rel.ForeignTable.ColumnNameGo}}) _, err = tx.Exec(`insert into {{schemaTable $dot.Dialect.LQ $dot.Dialect.RQ $dot.DriverName $dot.Schema .JoinTable}} ({{.JoinLocalColumn}}, {{.JoinForeignColumn}}) values ($1, $2)`, a.{{$rel.LocalTable.ColumnNameGo}}, b.{{$rel.ForeignTable.ColumnNameGo}})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
_, err = tx.Exec(`insert into {{schemaTable $dot.DriverName $dot.Schema .JoinTable}} ({{.JoinLocalColumn}}, {{.JoinForeignColumn}}) values ($1, $2)`, a.{{$rel.LocalTable.ColumnNameGo}}, c.{{$rel.ForeignTable.ColumnNameGo}}) _, err = tx.Exec(`insert into {{schemaTable $dot.Dialect.LQ $dot.Dialect.RQ $dot.DriverName $dot.Schema .JoinTable}} ({{.JoinLocalColumn}}, {{.JoinForeignColumn}}) values ($1, $2)`, a.{{$rel.LocalTable.ColumnNameGo}}, c.{{$rel.ForeignTable.ColumnNameGo}})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }