Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions placeholder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ var (
// Colon is a PlaceholderFormat instance that replaces placeholders with
// colon-prefixed positional placeholders (e.g. :1, :2, :3).
Colon = colonFormat{}

// Position is a PlaceholderFormat instance that replaces placeholders with
// @p-prefixed positional placeholders normally used with MSSQL drivers (e.g @p1, @p2)
Position = positionFormat{}
)

type questionFormat struct{}
Expand All @@ -46,6 +50,12 @@ func (colonFormat) ReplacePlaceholders(sql string) (string, error) {
return replacePositionalPlaceholders(sql, ":")
}

type positionFormat struct{}

func (positionFormat) ReplacePlaceholders(sql string) (string, error) {
return replacePositionalPlaceholders(sql, "@p")
}

// Placeholders returns a string with count ? placeholders joined with commas.
func Placeholders(count int) string {
if count < 1 {
Expand Down
6 changes: 6 additions & 0 deletions placeholder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ func TestColon(t *testing.T) {
assert.Equal(t, "x = :1 AND y = :2", s)
}

func TestPosition(t *testing.T) {
sql := "x = ? AND y = ?"
s, _ := Position.ReplacePlaceholders(sql)
assert.Equal(t, "x = @p1 AND y = @p2", s)
}

func TestPlaceholders(t *testing.T) {
assert.Equal(t, Placeholders(2), "?,?")
}
Expand Down