Source File
placeholder.go
Belonging Package
github.com/Masterminds/squirrel
package squirrel
import (
)
type PlaceholderFormat interface {
ReplacePlaceholders(sql string) (string, error)
}
type placeholderDebugger interface {
debugPlaceholder() string
}
Dollar = dollarFormat{}
Colon = colonFormat{}
AtP = atpFormat{}
)
type questionFormat struct{}
func (questionFormat) ( string) (string, error) {
return , nil
}
func (questionFormat) () string {
return "?"
}
type dollarFormat struct{}
func (dollarFormat) ( string) (string, error) {
return replacePositionalPlaceholders(, "$")
}
func (dollarFormat) () string {
return "$"
}
type colonFormat struct{}
func (colonFormat) ( string) (string, error) {
return replacePositionalPlaceholders(, ":")
}
func (colonFormat) () string {
return ":"
}
type atpFormat struct{}
func (atpFormat) ( string) (string, error) {
return replacePositionalPlaceholders(, "@p")
}
func (atpFormat) () string {
return "@p"
}
func ( int) string {
if < 1 {
return ""
}
return strings.Repeat(",?", )[1:]
}
func (, string) (string, error) {
:= &bytes.Buffer{}
:= 0
for {
:= strings.Index(, "?")
if == -1 {
break
}
if len([:]) > 1 && [:+2] == "??" { // escape ?? => ?
.WriteString([:])
.WriteString("?")
if len([:]) == 1 {
break
}
= [+2:]
} else {
++
.WriteString([:])
fmt.Fprintf(, "%s%d", , )
= [+1:]
}
}
.WriteString()
return .String(), nil
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |