From a280795a0021a213fca4daafcc34a95d13dd1491 Mon Sep 17 00:00:00 2001 From: Aaron L Date: Sat, 17 Jun 2017 23:18:40 -0700 Subject: [PATCH] Rename IndexPlaceholders -> UseIndexPlaceholders --- boilingcore/boilingcore.go | 2 +- boilingcore/config.go | 34 ------------------- drivers/interface_test.go | 4 +-- drivers/mocks/mock.go | 4 +-- queries/query.go | 2 +- queries/query_builders.go | 28 +++++++-------- queries/query_builders_test.go | 10 +++--- queries/reflect_test.go | 12 +++---- strmangle/strmangle.go | 6 ++-- templates/07_relationship_to_one_eager.tpl | 2 +- .../08_relationship_one_to_one_eager.tpl | 2 +- templates/09_relationship_to_many_eager.tpl | 4 +-- templates/10_relationship_to_one_setops.tpl | 4 +-- .../11_relationship_one_to_one_setops.tpl | 4 +-- templates/12_relationship_to_many_setops.tpl | 14 ++++---- templates/14_find.tpl | 2 +- templates/15_insert.tpl | 4 +-- templates/16_update.tpl | 8 ++--- templates/18_delete.tpl | 4 +-- templates/19_reload.tpl | 2 +- templates/20_exists.tpl | 4 +-- templates/singleton/boil_queries.tpl | 2 +- templates_test/relationship_to_many.tpl | 4 +-- 23 files changed, 64 insertions(+), 98 deletions(-) diff --git a/boilingcore/boilingcore.go b/boilingcore/boilingcore.go index 6bd7685ee..4328f9c20 100644 --- a/boilingcore/boilingcore.go +++ b/boilingcore/boilingcore.go @@ -326,7 +326,7 @@ func (s *State) initDriver(driverName string) error { s.Dialect.LQ = s.Driver.LeftQuote() s.Dialect.RQ = s.Driver.RightQuote() - s.Dialect.IndexPlaceholders = s.Driver.IndexPlaceholders() + s.Dialect.UseIndexPlaceholders = s.Driver.UseIndexPlaceholders() s.Dialect.UseTopClause = s.Driver.UseTopClause() return nil diff --git a/boilingcore/config.go b/boilingcore/config.go index 1760fc927..d3c794cd3 100644 --- a/boilingcore/config.go +++ b/boilingcore/config.go @@ -21,38 +21,4 @@ type Config struct { StructTagCasing string Imports importers.Collection - - Postgres PostgresConfig - MySQL MySQLConfig - MSSQL MSSQLConfig -} - -// PostgresConfig configures a postgres database -type PostgresConfig struct { - User string - Pass string - Host string - Port int - DBName string - SSLMode string -} - -// MySQLConfig configures a mysql database -type MySQLConfig struct { - User string - Pass string - Host string - Port int - DBName string - SSLMode string -} - -// MSSQLConfig configures a mysql database -type MSSQLConfig struct { - User string - Pass string - Host string - Port int - DBName string - SSLMode string } diff --git a/drivers/interface_test.go b/drivers/interface_test.go index df45d2c27..a922fa067 100644 --- a/drivers/interface_test.go +++ b/drivers/interface_test.go @@ -107,8 +107,8 @@ func (m testMockDriver) LeftQuote() byte { return '"' } -// IndexPlaceholders returns true to indicate fake support of indexed placeholders -func (m testMockDriver) IndexPlaceholders() bool { +// UseIndexPlaceholders returns true to indicate fake support of indexed placeholders +func (m testMockDriver) UseIndexPlaceholders() bool { return false } diff --git a/drivers/mocks/mock.go b/drivers/mocks/mock.go index 3b70c09bb..a91649e21 100644 --- a/drivers/mocks/mock.go +++ b/drivers/mocks/mock.go @@ -137,7 +137,7 @@ func (m *MockDriver) LeftQuote() byte { return '"' } -// IndexPlaceholders returns true to indicate fake support of indexed placeholders -func (m *MockDriver) IndexPlaceholders() bool { +// UseIndexPlaceholders returns true to indicate fake support of indexed placeholders +func (m *MockDriver) UseIndexPlaceholders() bool { return false } diff --git a/queries/query.go b/queries/query.go index b0594841f..6661f23e5 100644 --- a/queries/query.go +++ b/queries/query.go @@ -51,7 +51,7 @@ type Dialect struct { RQ byte // Bool flag indicating whether indexed // placeholders ($1) are used, or ? placeholders. - IndexPlaceholders bool + UseIndexPlaceholders bool // Bool flag indicating whether "TOP" or "LIMIT" clause // must be used for rows limitation UseTopClause bool diff --git a/queries/query_builders.go b/queries/query_builders.go index 9fd792d7e..f2bb42a0f 100644 --- a/queries/query_builders.go +++ b/queries/query_builders.go @@ -89,7 +89,7 @@ func buildSelectQuery(q *Query) (*bytes.Buffer, []interface{}) { args = append(args, j.args...) } var resp string - if q.dialect.IndexPlaceholders { + if q.dialect.UseIndexPlaceholders { resp, _ = convertQuestionMarks(joinBuf.String(), argsLen+1) } else { resp = joinBuf.String() @@ -166,7 +166,7 @@ func buildUpdateQuery(q *Query) (*bytes.Buffer, []interface{}) { setSlice := make([]string, len(cols)) for index, col := range cols { - setSlice[index] = fmt.Sprintf("%s = %s", col, strmangle.Placeholders(q.dialect.IndexPlaceholders, 1, index+1, 1)) + setSlice[index] = fmt.Sprintf("%s = %s", col, strmangle.Placeholders(q.dialect.UseIndexPlaceholders, 1, index+1, 1)) } fmt.Fprintf(buf, " SET %s", strings.Join(setSlice, ", ")) @@ -207,7 +207,7 @@ func BuildUpsertQueryMySQL(dia Dialect, tableName string, update, whitelist []st "INSERT IGNORE INTO %s (%s) VALUES (%s)", tableName, columns, - strmangle.Placeholders(dia.IndexPlaceholders, len(whitelist), 1, 1), + strmangle.Placeholders(dia.UseIndexPlaceholders, len(whitelist), 1, 1), ) return buf.String() } @@ -217,7 +217,7 @@ func BuildUpsertQueryMySQL(dia Dialect, tableName string, update, whitelist []st "INSERT INTO %s (%s) VALUES (%s) ON DUPLICATE KEY UPDATE ", tableName, columns, - strmangle.Placeholders(dia.IndexPlaceholders, len(whitelist), 1, 1), + strmangle.Placeholders(dia.UseIndexPlaceholders, len(whitelist), 1, 1), ) for i, v := range update { @@ -247,7 +247,7 @@ func BuildUpsertQueryPostgres(dia Dialect, tableName string, updateOnConflict bo if len(whitelist) != 0 { columns = fmt.Sprintf("(%s) VALUES (%s)", strings.Join(whitelist, ", "), - strmangle.Placeholders(dia.IndexPlaceholders, len(whitelist), 1, 1)) + strmangle.Placeholders(dia.UseIndexPlaceholders, len(whitelist), 1, 1)) } fmt.Fprintf( @@ -294,7 +294,7 @@ func BuildUpsertQueryMSSQL(dia Dialect, tableName string, primary, update, inser fmt.Fprintf(buf, "MERGE INTO %s as [t]\n", tableName) fmt.Fprintf(buf, "USING (SELECT %s) as [s] ([%s])\n", - strmangle.Placeholders(dia.IndexPlaceholders, len(primary), startIndex, 1), + strmangle.Placeholders(dia.UseIndexPlaceholders, len(primary), startIndex, 1), strings.Join(primary, string(dia.RQ)+","+string(dia.LQ))) fmt.Fprint(buf, "ON (") for i, v := range primary { @@ -315,7 +315,7 @@ func BuildUpsertQueryMSSQL(dia Dialect, tableName string, primary, update, inser fmt.Fprint(buf, "WHEN NOT MATCHED THEN ") fmt.Fprintf(buf, "INSERT (%s) VALUES (%s)", strings.Join(insert, ", "), - strmangle.Placeholders(dia.IndexPlaceholders, len(insert), startIndex, 1)) + strmangle.Placeholders(dia.UseIndexPlaceholders, len(insert), startIndex, 1)) if len(output) > 0 { fmt.Fprintf(buf, "\nOUTPUT INSERTED.[%s];", strings.Join(output, "],INSERTED.[")) @@ -343,7 +343,7 @@ func writeModifiers(q *Query, buf *bytes.Buffer, args *[]interface{}) { *args = append(*args, j.args...) } var resp string - if q.dialect.IndexPlaceholders { + if q.dialect.UseIndexPlaceholders { resp, _ = convertQuestionMarks(havingBuf.String(), argsLen+1) } else { resp = havingBuf.String() @@ -471,7 +471,7 @@ func whereClause(q *Query, startAt int) (string, []interface{}) { } var resp string - if q.dialect.IndexPlaceholders { + if q.dialect.UseIndexPlaceholders { resp, _ = convertQuestionMarks(buf.String(), startAt) } else { resp = buf.String() @@ -515,7 +515,7 @@ func inClause(q *Query, startAt int) (string, []interface{}) { // column name side, however if this case is being hit then the regexp // probably needs adjustment, or the user is passing in invalid clauses. if matches == nil { - clause, count := convertInQuestionMarks(q.dialect.IndexPlaceholders, in.clause, startAt, 1, ln) + clause, count := convertInQuestionMarks(q.dialect.UseIndexPlaceholders, in.clause, startAt, 1, ln) buf.WriteString(clause) startAt = startAt + count } else { @@ -530,7 +530,7 @@ func inClause(q *Query, startAt int) (string, []interface{}) { var leftClause string var leftCount int - if q.dialect.IndexPlaceholders { + if q.dialect.UseIndexPlaceholders { leftClause, leftCount = convertQuestionMarks(strings.Join(cols, ","), startAt) } else { // Count the number of cols that are question marks, so we know @@ -542,7 +542,7 @@ func inClause(q *Query, startAt int) (string, []interface{}) { } leftClause = strings.Join(cols, ",") } - rightClause, rightCount := convertInQuestionMarks(q.dialect.IndexPlaceholders, rightSide, startAt+leftCount, groupAt, ln-leftCount) + rightClause, rightCount := convertInQuestionMarks(q.dialect.UseIndexPlaceholders, rightSide, startAt+leftCount, groupAt, ln-leftCount) buf.WriteString(leftClause) buf.WriteString(" IN ") buf.WriteString(rightClause) @@ -560,7 +560,7 @@ func inClause(q *Query, startAt int) (string, []interface{}) { // It uses groupAt to determine how many placeholders should be in each group, // for example, groupAt 2 would result in: (($1,$2),($3,$4)) // and groupAt 1 would result in ($1,$2,$3,$4) -func convertInQuestionMarks(indexPlaceholders bool, clause string, startAt, groupAt, total int) (string, int) { +func convertInQuestionMarks(UseIndexPlaceholders bool, clause string, startAt, groupAt, total int) (string, int) { if startAt == 0 || len(clause) == 0 { panic("Not a valid start number.") } @@ -582,7 +582,7 @@ func convertInQuestionMarks(indexPlaceholders bool, clause string, startAt, grou paramBuf.WriteString(clause[:foundAt]) paramBuf.WriteByte('(') - paramBuf.WriteString(strmangle.Placeholders(indexPlaceholders, total, startAt, groupAt)) + paramBuf.WriteString(strmangle.Placeholders(UseIndexPlaceholders, total, startAt, groupAt)) paramBuf.WriteByte(')') paramBuf.WriteString(clause[foundAt+1:]) diff --git a/queries/query_builders_test.go b/queries/query_builders_test.go index a8fd4db9e..d5dd9b2bf 100644 --- a/queries/query_builders_test.go +++ b/queries/query_builders_test.go @@ -97,7 +97,7 @@ func TestBuildQuery(t *testing.T) { for i, test := range tests { filename := filepath.Join("_fixtures", fmt.Sprintf("%02d.sql", i)) - test.q.dialect = &Dialect{LQ: '"', RQ: '"', IndexPlaceholders: true} + test.q.dialect = &Dialect{LQ: '"', RQ: '"', UseIndexPlaceholders: true} out, args := buildQuery(test.q) if *writeGoldenFiles { @@ -150,7 +150,7 @@ func TestWriteStars(t *testing.T) { } for i, test := range tests { - test.In.dialect = &Dialect{LQ: '"', RQ: '"', IndexPlaceholders: true} + test.In.dialect = &Dialect{LQ: '"', RQ: '"', UseIndexPlaceholders: true} selects := writeStars(&test.In) if !reflect.DeepEqual(selects, test.Out) { t.Errorf("writeStar test fail %d\nwant: %v\ngot: %v", i, test.Out, selects) @@ -277,7 +277,7 @@ func TestWhereClause(t *testing.T) { } for i, test := range tests { - test.q.dialect = &Dialect{LQ: '"', RQ: '"', IndexPlaceholders: true} + test.q.dialect = &Dialect{LQ: '"', RQ: '"', UseIndexPlaceholders: true} result, _ := whereClause(&test.q, 1) if result != test.expect { t.Errorf("%d) Mismatch between expect and result:\n%s\n%s\n", i, test.expect, result) @@ -410,7 +410,7 @@ func TestInClause(t *testing.T) { } for i, test := range tests { - test.q.dialect = &Dialect{LQ: '"', RQ: '"', IndexPlaceholders: true} + test.q.dialect = &Dialect{LQ: '"', RQ: '"', UseIndexPlaceholders: true} result, args := inClause(&test.q, 1) if result != test.expect { t.Errorf("%d) Mismatch between expect and result:\n%s\n%s\n", i, test.expect, result) @@ -524,7 +524,7 @@ func TestWriteAsStatements(t *testing.T) { `a.clown.run`, `COUNT(a)`, }, - dialect: &Dialect{LQ: '"', RQ: '"', IndexPlaceholders: true}, + dialect: &Dialect{LQ: '"', RQ: '"', UseIndexPlaceholders: true}, } expect := []string{ diff --git a/queries/reflect_test.go b/queries/reflect_test.go index bad403d36..0e861ca7e 100644 --- a/queries/reflect_test.go +++ b/queries/reflect_test.go @@ -43,7 +43,7 @@ func TestBindStruct(t *testing.T) { query := &Query{ from: []string{"fun"}, - dialect: &Dialect{LQ: '"', RQ: '"', IndexPlaceholders: true}, + dialect: &Dialect{LQ: '"', RQ: '"', UseIndexPlaceholders: true}, } db, mock, err := sqlmock.New() @@ -83,7 +83,7 @@ func TestBindSlice(t *testing.T) { query := &Query{ from: []string{"fun"}, - dialect: &Dialect{LQ: '"', RQ: '"', IndexPlaceholders: true}, + dialect: &Dialect{LQ: '"', RQ: '"', UseIndexPlaceholders: true}, } db, mock, err := sqlmock.New() @@ -134,7 +134,7 @@ func TestBindPtrSlice(t *testing.T) { query := &Query{ from: []string{"fun"}, - dialect: &Dialect{LQ: '"', RQ: '"', IndexPlaceholders: true}, + dialect: &Dialect{LQ: '"', RQ: '"', UseIndexPlaceholders: true}, } db, mock, err := sqlmock.New() @@ -443,7 +443,7 @@ func TestBindSingular(t *testing.T) { query := &Query{ from: []string{"fun"}, - dialect: &Dialect{LQ: '"', RQ: '"', IndexPlaceholders: true}, + dialect: &Dialect{LQ: '"', RQ: '"', UseIndexPlaceholders: true}, } db, mock, err := sqlmock.New() @@ -488,7 +488,7 @@ func TestBind_InnerJoin(t *testing.T) { query := &Query{ from: []string{"fun"}, joins: []join{{kind: JoinInner, clause: "happy as h on fun.id = h.fun_id"}}, - dialect: &Dialect{LQ: '"', RQ: '"', IndexPlaceholders: true}, + dialect: &Dialect{LQ: '"', RQ: '"', UseIndexPlaceholders: true}, } db, mock, err := sqlmock.New() @@ -542,7 +542,7 @@ func TestBind_InnerJoinSelect(t *testing.T) { }{} query := &Query{ - dialect: &Dialect{LQ: '"', RQ: '"', IndexPlaceholders: true}, + dialect: &Dialect{LQ: '"', RQ: '"', UseIndexPlaceholders: true}, selectCols: []string{"fun.id", "h.id"}, from: []string{"fun"}, joins: []join{{kind: JoinInner, clause: "happy as h on fun.happy_id = h.id"}}, diff --git a/strmangle/strmangle.go b/strmangle/strmangle.go index b3c16bc1d..4a55d331b 100644 --- a/strmangle/strmangle.go +++ b/strmangle/strmangle.go @@ -445,8 +445,8 @@ func PrefixStringSlice(str string, strs []string) []string { // Placeholders generates the SQL statement placeholders for in queries. // For example, ($1,$2,$3),($4,$5,$6) etc. // It will start counting placeholders at "start". -// If indexPlaceholders is false, it will convert to ? instead of $1 etc. -func Placeholders(indexPlaceholders bool, count int, start int, group int) string { +// If useIndexPlaceholders is false, it will convert to ? instead of $1 etc. +func Placeholders(useIndexPlaceholders bool, count int, start int, group int) string { buf := GetBuffer() defer PutBuffer(buf) @@ -465,7 +465,7 @@ func Placeholders(indexPlaceholders bool, count int, start int, group int) strin buf.WriteByte(',') } } - if indexPlaceholders { + if useIndexPlaceholders { buf.WriteString(fmt.Sprintf("$%d", start+i)) } else { buf.WriteByte('?') diff --git a/templates/07_relationship_to_one_eager.tpl b/templates/07_relationship_to_one_eager.tpl index dd1481aa9..f31ff9f90 100644 --- a/templates/07_relationship_to_one_eager.tpl +++ b/templates/07_relationship_to_one_eager.tpl @@ -36,7 +36,7 @@ func ({{$varNameSingular}}L) Load{{$txt.Function.Name}}(e boil.Executor, singula query := fmt.Sprintf( "select * from {{.ForeignTable | $dot.SchemaTable}} where {{.ForeignColumn | $dot.Quotes}} in (%s)", - strmangle.Placeholders(dialect.IndexPlaceholders, count, 1, 1), + strmangle.Placeholders(dialect.UseIndexPlaceholders, count, 1, 1), ) if boil.DebugMode { diff --git a/templates/08_relationship_one_to_one_eager.tpl b/templates/08_relationship_one_to_one_eager.tpl index 37d1af086..5c2a34399 100644 --- a/templates/08_relationship_one_to_one_eager.tpl +++ b/templates/08_relationship_one_to_one_eager.tpl @@ -36,7 +36,7 @@ func ({{$varNameSingular}}L) Load{{$txt.Function.Name}}(e boil.Executor, singula query := fmt.Sprintf( "select * from {{.ForeignTable | $dot.SchemaTable}} where {{.ForeignColumn | $dot.Quotes}} in (%s)", - strmangle.Placeholders(dialect.IndexPlaceholders, count, 1, 1), + strmangle.Placeholders(dialect.UseIndexPlaceholders, count, 1, 1), ) if boil.DebugMode { diff --git a/templates/09_relationship_to_many_eager.tpl b/templates/09_relationship_to_many_eager.tpl index 16031882e..ec3729e98 100644 --- a/templates/09_relationship_to_many_eager.tpl +++ b/templates/09_relationship_to_many_eager.tpl @@ -39,12 +39,12 @@ func ({{$varNameSingular}}L) Load{{$txt.Function.Name}}(e boil.Executor, singula {{- $schemaJoinTable := .JoinTable | $dot.SchemaTable -}} query := fmt.Sprintf( "select {{id 0 | $dot.Quotes}}.*, {{id 1 | $dot.Quotes}}.{{.JoinLocalColumn | $dot.Quotes}} from {{$schemaForeignTable}} as {{id 0 | $dot.Quotes}} inner join {{$schemaJoinTable}} as {{id 1 | $dot.Quotes}} on {{id 0 | $dot.Quotes}}.{{.ForeignColumn | $dot.Quotes}} = {{id 1 | $dot.Quotes}}.{{.JoinForeignColumn | $dot.Quotes}} where {{id 1 | $dot.Quotes}}.{{.JoinLocalColumn | $dot.Quotes}} in (%s)", - strmangle.Placeholders(dialect.IndexPlaceholders, count, 1, 1), + strmangle.Placeholders(dialect.UseIndexPlaceholders, count, 1, 1), ) {{else -}} query := fmt.Sprintf( "select * from {{$schemaForeignTable}} where {{.ForeignColumn | $dot.Quotes}} in (%s)", - strmangle.Placeholders(dialect.IndexPlaceholders, count, 1, 1), + strmangle.Placeholders(dialect.UseIndexPlaceholders, count, 1, 1), ) {{end -}} diff --git a/templates/10_relationship_to_one_setops.tpl b/templates/10_relationship_to_one_setops.tpl index 14f726e5f..98ff38147 100644 --- a/templates/10_relationship_to_one_setops.tpl +++ b/templates/10_relationship_to_one_setops.tpl @@ -47,8 +47,8 @@ func (o *{{$txt.LocalTable.NameGo}}) Set{{$txt.Function.Name}}(exec boil.Executo updateQuery := fmt.Sprintf( "UPDATE {{$schemaTable}} SET %s WHERE %s", - strmangle.SetParamNames("{{$dot.LQ}}", "{{$dot.RQ}}", {{if $dot.Dialect.IndexPlaceholders}}1{{else}}0{{end}}, []string{{"{"}}"{{.Column}}"{{"}"}}), - strmangle.WhereClause("{{$dot.LQ}}", "{{$dot.RQ}}", {{if $dot.Dialect.IndexPlaceholders}}2{{else}}0{{end}}, {{$varNameSingular}}PrimaryKeyColumns), + strmangle.SetParamNames("{{$dot.LQ}}", "{{$dot.RQ}}", {{if $dot.Dialect.UseIndexPlaceholders}}1{{else}}0{{end}}, []string{{"{"}}"{{.Column}}"{{"}"}}), + strmangle.WhereClause("{{$dot.LQ}}", "{{$dot.RQ}}", {{if $dot.Dialect.UseIndexPlaceholders}}2{{else}}0{{end}}, {{$varNameSingular}}PrimaryKeyColumns), ) values := []interface{}{related.{{$txt.ForeignTable.ColumnNameGo}}, o.{{$dot.Table.PKey.Columns | stringMap $dot.StringFuncs.titleCase | join ", o."}}{{"}"}} diff --git a/templates/11_relationship_one_to_one_setops.tpl b/templates/11_relationship_one_to_one_setops.tpl index 826eec2f4..c73eecdac 100644 --- a/templates/11_relationship_one_to_one_setops.tpl +++ b/templates/11_relationship_one_to_one_setops.tpl @@ -53,8 +53,8 @@ func (o *{{$txt.LocalTable.NameGo}}) Set{{$txt.Function.Name}}(exec boil.Executo } else { updateQuery := fmt.Sprintf( "UPDATE {{$foreignSchemaTable}} SET %s WHERE %s", - strmangle.SetParamNames("{{$dot.LQ}}", "{{$dot.RQ}}", {{if $dot.Dialect.IndexPlaceholders}}1{{else}}0{{end}}, []string{{"{"}}"{{.ForeignColumn}}"{{"}"}}), - strmangle.WhereClause("{{$dot.LQ}}", "{{$dot.RQ}}", {{if $dot.Dialect.IndexPlaceholders}}2{{else}}0{{end}}, {{$foreignVarNameSingular}}PrimaryKeyColumns), + strmangle.SetParamNames("{{$dot.LQ}}", "{{$dot.RQ}}", {{if $dot.Dialect.UseIndexPlaceholders}}1{{else}}0{{end}}, []string{{"{"}}"{{.ForeignColumn}}"{{"}"}}), + strmangle.WhereClause("{{$dot.LQ}}", "{{$dot.RQ}}", {{if $dot.Dialect.UseIndexPlaceholders}}2{{else}}0{{end}}, {{$foreignVarNameSingular}}PrimaryKeyColumns), ) values := []interface{}{o.{{$txt.LocalTable.ColumnNameGo}}, related.{{$foreignPKeyCols | stringMap $dot.StringFuncs.titleCase | join ", related."}}{{"}"}} diff --git a/templates/12_relationship_to_many_setops.tpl b/templates/12_relationship_to_many_setops.tpl index 06159eedc..9a8ee7afe 100644 --- a/templates/12_relationship_to_many_setops.tpl +++ b/templates/12_relationship_to_many_setops.tpl @@ -60,8 +60,8 @@ func (o *{{$txt.LocalTable.NameGo}}) Add{{$txt.Function.Name}}(exec boil.Executo }{{if not .ToJoinTable}} else { updateQuery := fmt.Sprintf( "UPDATE {{$foreignSchemaTable}} SET %s WHERE %s", - strmangle.SetParamNames("{{$dot.LQ}}", "{{$dot.RQ}}", {{if $dot.Dialect.IndexPlaceholders}}1{{else}}0{{end}}, []string{{"{"}}"{{.ForeignColumn}}"{{"}"}}), - strmangle.WhereClause("{{$dot.LQ}}", "{{$dot.RQ}}", {{if $dot.Dialect.IndexPlaceholders}}2{{else}}0{{end}}, {{$foreignVarNameSingular}}PrimaryKeyColumns), + strmangle.SetParamNames("{{$dot.LQ}}", "{{$dot.RQ}}", {{if $dot.Dialect.UseIndexPlaceholders}}1{{else}}0{{end}}, []string{{"{"}}"{{.ForeignColumn}}"{{"}"}}), + strmangle.WhereClause("{{$dot.LQ}}", "{{$dot.RQ}}", {{if $dot.Dialect.UseIndexPlaceholders}}2{{else}}0{{end}}, {{$foreignVarNameSingular}}PrimaryKeyColumns), ) values := []interface{}{o.{{$txt.LocalTable.ColumnNameGo}}, rel.{{$foreignPKeyCols | stringMap $dot.StringFuncs.titleCase | join ", rel."}}{{"}"}} @@ -83,7 +83,7 @@ func (o *{{$txt.LocalTable.NameGo}}) Add{{$txt.Function.Name}}(exec boil.Executo {{if .ToJoinTable -}} for _, rel := range related { - query := "insert into {{.JoinTable | $dot.SchemaTable}} ({{.JoinLocalColumn | $dot.Quotes}}, {{.JoinForeignColumn | $dot.Quotes}}) values {{if $dot.Dialect.IndexPlaceholders}}($1, $2){{else}}(?, ?){{end}}" + query := "insert into {{.JoinTable | $dot.SchemaTable}} ({{.JoinLocalColumn | $dot.Quotes}}, {{.JoinForeignColumn | $dot.Quotes}}) values {{if $dot.Dialect.UseIndexPlaceholders}}($1, $2){{else}}(?, ?){{end}}" values := []interface{}{{"{"}}o.{{$txt.LocalTable.ColumnNameGo}}, rel.{{$txt.ForeignTable.ColumnNameGo}}} if boil.DebugMode { @@ -177,10 +177,10 @@ func (o *{{$txt.LocalTable.NameGo}}) Set{{$txt.Function.Name}}GP(insert bool, re // Sets related.R.{{$txt.Function.ForeignName}}'s {{$txt.Function.Name}} accordingly. func (o *{{$txt.LocalTable.NameGo}}) Set{{$txt.Function.Name}}(exec boil.Executor, insert bool, related ...*{{$txt.ForeignTable.NameGo}}) error { {{if .ToJoinTable -}} - query := "delete from {{.JoinTable | $dot.SchemaTable}} where {{.JoinLocalColumn | $dot.Quotes}} = {{if $dot.Dialect.IndexPlaceholders}}$1{{else}}?{{end}}" + query := "delete from {{.JoinTable | $dot.SchemaTable}} where {{.JoinLocalColumn | $dot.Quotes}} = {{if $dot.Dialect.UseIndexPlaceholders}}$1{{else}}?{{end}}" values := []interface{}{{"{"}}o.{{$txt.LocalTable.ColumnNameGo}}} {{else -}} - query := "update {{.ForeignTable | $dot.SchemaTable}} set {{.ForeignColumn | $dot.Quotes}} = null where {{.ForeignColumn | $dot.Quotes}} = {{if $dot.Dialect.IndexPlaceholders}}$1{{else}}?{{end}}" + query := "update {{.ForeignTable | $dot.SchemaTable}} set {{.ForeignColumn | $dot.Quotes}} = null where {{.ForeignColumn | $dot.Quotes}} = {{if $dot.Dialect.UseIndexPlaceholders}}$1{{else}}?{{end}}" values := []interface{}{{"{"}}o.{{$txt.LocalTable.ColumnNameGo}}} {{end -}} if boil.DebugMode { @@ -251,8 +251,8 @@ func (o *{{$txt.LocalTable.NameGo}}) Remove{{$txt.Function.Name}}(exec boil.Exec var err error {{if .ToJoinTable -}} query := fmt.Sprintf( - "delete from {{.JoinTable | $dot.SchemaTable}} where {{.JoinLocalColumn | $dot.Quotes}} = {{if $dot.Dialect.IndexPlaceholders}}$1{{else}}?{{end}} and {{.JoinForeignColumn | $dot.Quotes}} in (%s)", - strmangle.Placeholders(dialect.IndexPlaceholders, len(related), 2, 1), + "delete from {{.JoinTable | $dot.SchemaTable}} where {{.JoinLocalColumn | $dot.Quotes}} = {{if $dot.Dialect.UseIndexPlaceholders}}$1{{else}}?{{end}} and {{.JoinForeignColumn | $dot.Quotes}} in (%s)", + strmangle.Placeholders(dialect.UseIndexPlaceholders, len(related), 2, 1), ) values := []interface{}{{"{"}}o.{{$txt.LocalTable.ColumnNameGo}}} for _, rel := range related { diff --git a/templates/14_find.tpl b/templates/14_find.tpl index 097f18407..b52818538 100644 --- a/templates/14_find.tpl +++ b/templates/14_find.tpl @@ -28,7 +28,7 @@ func Find{{$tableNameSingular}}(exec boil.Executor, {{$pkArgs}}, selectCols ...s sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",") } query := fmt.Sprintf( - "select %s from {{.Table.Name | .SchemaTable}} where {{if .Dialect.IndexPlaceholders}}{{whereClause .LQ .RQ 1 .Table.PKey.Columns}}{{else}}{{whereClause .LQ .RQ 0 .Table.PKey.Columns}}{{end}}", sel, + "select %s from {{.Table.Name | .SchemaTable}} where {{if .Dialect.UseIndexPlaceholders}}{{whereClause .LQ .RQ 1 .Table.PKey.Columns}}{{else}}{{whereClause .LQ .RQ 0 .Table.PKey.Columns}}{{end}}", sel, ) q := queries.Raw(exec, query, {{$pkNames | join ", "}}) diff --git a/templates/15_insert.tpl b/templates/15_insert.tpl index 870e20d85..72e406788 100644 --- a/templates/15_insert.tpl +++ b/templates/15_insert.tpl @@ -66,7 +66,7 @@ func (o *{{$tableNameSingular}}) Insert(exec boil.Executor, whitelist ... string return err } if len(wl) != 0 { - cache.query = fmt.Sprintf("INSERT INTO {{$schemaTable}} ({{.LQ}}%s{{.RQ}}) %%sVALUES (%s)%%s", strings.Join(wl, "{{.RQ}},{{.LQ}}"), strmangle.Placeholders(dialect.IndexPlaceholders, len(wl), 1, 1)) + cache.query = fmt.Sprintf("INSERT INTO {{$schemaTable}} ({{.LQ}}%s{{.RQ}}) %%sVALUES (%s)%%s", strings.Join(wl, "{{.RQ}},{{.LQ}}"), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1)) } else { {{if eq .DriverName "mysql" -}} cache.query = "INSERT INTO {{$schemaTable}} () VALUES ()" @@ -79,7 +79,7 @@ func (o *{{$tableNameSingular}}) Insert(exec boil.Executor, whitelist ... string if len(cache.retMapping) != 0 { {{if .UseLastInsertID -}} - cache.retQuery = fmt.Sprintf("SELECT {{.LQ}}%s{{.RQ}} FROM {{$schemaTable}} WHERE %s", strings.Join(returnColumns, "{{.RQ}},{{.LQ}}"), strmangle.WhereClause("{{.LQ}}", "{{.RQ}}", {{if .Dialect.IndexPlaceholders}}1{{else}}0{{end}}, {{$varNameSingular}}PrimaryKeyColumns)) + cache.retQuery = fmt.Sprintf("SELECT {{.LQ}}%s{{.RQ}} FROM {{$schemaTable}} WHERE %s", strings.Join(returnColumns, "{{.RQ}},{{.LQ}}"), strmangle.WhereClause("{{.LQ}}", "{{.RQ}}", {{if .Dialect.UseIndexPlaceholders}}1{{else}}0{{end}}, {{$varNameSingular}}PrimaryKeyColumns)) {{else -}} {{if ne .DriverName "mssql" -}} queryReturning = fmt.Sprintf(" RETURNING {{.LQ}}%s{{.RQ}}", strings.Join(returnColumns, "{{.RQ}},{{.LQ}}")) diff --git a/templates/16_update.tpl b/templates/16_update.tpl index 50c7f4910..27d5787dd 100644 --- a/templates/16_update.tpl +++ b/templates/16_update.tpl @@ -66,8 +66,8 @@ func (o *{{$tableNameSingular}}) Update(exec boil.Executor, whitelist ... string } cache.query = fmt.Sprintf("UPDATE {{$schemaTable}} SET %s WHERE %s", - strmangle.SetParamNames("{{.LQ}}", "{{.RQ}}", {{if .Dialect.IndexPlaceholders}}1{{else}}0{{end}}, wl), - strmangle.WhereClause("{{.LQ}}", "{{.RQ}}", {{if .Dialect.IndexPlaceholders}}len(wl)+1{{else}}0{{end}}, {{$varNameSingular}}PrimaryKeyColumns), + strmangle.SetParamNames("{{.LQ}}", "{{.RQ}}", {{if .Dialect.UseIndexPlaceholders}}1{{else}}0{{end}}, wl), + strmangle.WhereClause("{{.LQ}}", "{{.RQ}}", {{if .Dialect.UseIndexPlaceholders}}len(wl)+1{{else}}0{{end}}, {{$varNameSingular}}PrimaryKeyColumns), ) cache.valueMapping, err = queries.BindMapping({{$varNameSingular}}Type, {{$varNameSingular}}Mapping, append(wl, {{$varNameSingular}}PrimaryKeyColumns...)) if err != nil { @@ -166,8 +166,8 @@ func (o {{$tableNameSingular}}Slice) UpdateAll(exec boil.Executor, cols M) error } sql := fmt.Sprintf("UPDATE {{$schemaTable}} SET %s WHERE %s", - strmangle.SetParamNames("{{.LQ}}", "{{.RQ}}", {{if .Dialect.IndexPlaceholders}}1{{else}}0{{end}}, colNames), - strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), {{if .Dialect.IndexPlaceholders}}len(colNames)+1{{else}}0{{end}}, {{$varNameSingular}}PrimaryKeyColumns, len(o))) + strmangle.SetParamNames("{{.LQ}}", "{{.RQ}}", {{if .Dialect.UseIndexPlaceholders}}1{{else}}0{{end}}, colNames), + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), {{if .Dialect.UseIndexPlaceholders}}len(colNames)+1{{else}}0{{end}}, {{$varNameSingular}}PrimaryKeyColumns, len(o))) if boil.DebugMode { fmt.Fprintln(boil.DebugWriter, sql) diff --git a/templates/18_delete.tpl b/templates/18_delete.tpl index f2ddbb6de..1aa0b290a 100644 --- a/templates/18_delete.tpl +++ b/templates/18_delete.tpl @@ -43,7 +43,7 @@ func (o *{{$tableNameSingular}}) Delete(exec boil.Executor) error { {{- end}} args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), {{$varNameSingular}}PrimaryKeyMapping) - sql := "DELETE FROM {{$schemaTable}} WHERE {{if .Dialect.IndexPlaceholders}}{{whereClause .LQ .RQ 1 .Table.PKey.Columns}}{{else}}{{whereClause .LQ .RQ 0 .Table.PKey.Columns}}{{end}}" + sql := "DELETE FROM {{$schemaTable}} WHERE {{if .Dialect.UseIndexPlaceholders}}{{whereClause .LQ .RQ 1 .Table.PKey.Columns}}{{else}}{{whereClause .LQ .RQ 0 .Table.PKey.Columns}}{{end}}" if boil.DebugMode { fmt.Fprintln(boil.DebugWriter, sql) @@ -136,7 +136,7 @@ func (o {{$tableNameSingular}}Slice) DeleteAll(exec boil.Executor) error { } sql := "DELETE FROM {{$schemaTable}} WHERE " + - strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), {{if .Dialect.IndexPlaceholders}}1{{else}}0{{end}}, {{$varNameSingular}}PrimaryKeyColumns, len(o)) + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), {{if .Dialect.UseIndexPlaceholders}}1{{else}}0{{end}}, {{$varNameSingular}}PrimaryKeyColumns, len(o)) if boil.DebugMode { fmt.Fprintln(boil.DebugWriter, sql) diff --git a/templates/19_reload.tpl b/templates/19_reload.tpl index b1201b8af..271df5fdc 100644 --- a/templates/19_reload.tpl +++ b/templates/19_reload.tpl @@ -80,7 +80,7 @@ func (o *{{$tableNameSingular}}Slice) ReloadAll(exec boil.Executor) error { } sql := "SELECT {{$schemaTable}}.* FROM {{$schemaTable}} WHERE " + - strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), {{if .Dialect.IndexPlaceholders}}1{{else}}0{{end}}, {{$varNameSingular}}PrimaryKeyColumns, len(*o)) + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), {{if .Dialect.UseIndexPlaceholders}}1{{else}}0{{end}}, {{$varNameSingular}}PrimaryKeyColumns, len(*o)) q := queries.Raw(exec, sql, args...) diff --git a/templates/20_exists.tpl b/templates/20_exists.tpl index 22a67a052..2ae35dab4 100644 --- a/templates/20_exists.tpl +++ b/templates/20_exists.tpl @@ -7,9 +7,9 @@ func {{$tableNameSingular}}Exists(exec boil.Executor, {{$pkArgs}}) (bool, error) { var exists bool {{if eq .DriverName "mssql" -}} - sql := "select case when exists(select top(1) 1 from {{$schemaTable}} where {{if .Dialect.IndexPlaceholders}}{{whereClause .LQ .RQ 1 .Table.PKey.Columns}}{{else}}{{whereClause .LQ .RQ 0 .Table.PKey.Columns}}{{end}}) then 1 else 0 end" + sql := "select case when exists(select top(1) 1 from {{$schemaTable}} where {{if .Dialect.UseIndexPlaceholders}}{{whereClause .LQ .RQ 1 .Table.PKey.Columns}}{{else}}{{whereClause .LQ .RQ 0 .Table.PKey.Columns}}{{end}}) then 1 else 0 end" {{- else -}} - sql := "select exists(select 1 from {{$schemaTable}} where {{if .Dialect.IndexPlaceholders}}{{whereClause .LQ .RQ 1 .Table.PKey.Columns}}{{else}}{{whereClause .LQ .RQ 0 .Table.PKey.Columns}}{{end}} limit 1)" + sql := "select exists(select 1 from {{$schemaTable}} where {{if .Dialect.UseIndexPlaceholders}}{{whereClause .LQ .RQ 1 .Table.PKey.Columns}}{{else}}{{whereClause .LQ .RQ 0 .Table.PKey.Columns}}{{end}} limit 1)" {{- end}} if boil.DebugMode { diff --git a/templates/singleton/boil_queries.tpl b/templates/singleton/boil_queries.tpl index 3883e8e2c..5d735ed46 100644 --- a/templates/singleton/boil_queries.tpl +++ b/templates/singleton/boil_queries.tpl @@ -1,7 +1,7 @@ var dialect = queries.Dialect{ LQ: 0x{{printf "%x" .Dialect.LQ}}, RQ: 0x{{printf "%x" .Dialect.RQ}}, - IndexPlaceholders: {{.Dialect.IndexPlaceholders}}, + UseIndexPlaceholders: {{.Dialect.UseIndexPlaceholders}}, UseTopClause: {{.Dialect.UseTopClause}}, } diff --git a/templates_test/relationship_to_many.tpl b/templates_test/relationship_to_many.tpl index 0402609cc..e9407f86c 100644 --- a/templates_test/relationship_to_many.tpl +++ b/templates_test/relationship_to_many.tpl @@ -44,11 +44,11 @@ func test{{$txt.LocalTable.NameGo}}ToMany{{$txt.Function.Name}}(t *testing.T) { } {{if .ToJoinTable -}} - _, err = tx.Exec("insert into {{.JoinTable | $dot.SchemaTable}} ({{.JoinLocalColumn | $dot.Quotes}}, {{.JoinForeignColumn | $dot.Quotes}}) values {{if $dot.Dialect.IndexPlaceholders}}($1, $2){{else}}(?, ?){{end}}", a.{{$txt.LocalTable.ColumnNameGo}}, b.{{$txt.ForeignTable.ColumnNameGo}}) + _, err = tx.Exec("insert into {{.JoinTable | $dot.SchemaTable}} ({{.JoinLocalColumn | $dot.Quotes}}, {{.JoinForeignColumn | $dot.Quotes}}) values {{if $dot.Dialect.UseIndexPlaceholders}}($1, $2){{else}}(?, ?){{end}}", a.{{$txt.LocalTable.ColumnNameGo}}, b.{{$txt.ForeignTable.ColumnNameGo}}) if err != nil { t.Fatal(err) } - _, err = tx.Exec("insert into {{.JoinTable | $dot.SchemaTable}} ({{.JoinLocalColumn | $dot.Quotes}}, {{.JoinForeignColumn | $dot.Quotes}}) values {{if $dot.Dialect.IndexPlaceholders}}($1, $2){{else}}(?, ?){{end}}", a.{{$txt.LocalTable.ColumnNameGo}}, c.{{$txt.ForeignTable.ColumnNameGo}}) + _, err = tx.Exec("insert into {{.JoinTable | $dot.SchemaTable}} ({{.JoinLocalColumn | $dot.Quotes}}, {{.JoinForeignColumn | $dot.Quotes}}) values {{if $dot.Dialect.UseIndexPlaceholders}}($1, $2){{else}}(?, ?){{end}}", a.{{$txt.LocalTable.ColumnNameGo}}, c.{{$txt.ForeignTable.ColumnNameGo}}) if err != nil { t.Fatal(err) }