Source File
squirrel.go
Belonging Package
github.com/Masterminds/squirrel
package squirrel
import (
)
type rawSqlizer interface {
toSqlRaw() (string, []interface{}, error)
}
type QueryRower interface {
QueryRow(query string, args ...interface{}) RowScanner
}
type BaseRunner interface {
Execer
Queryer
}
type Runner interface {
Execer
Queryer
QueryRower
}
func ( StdSql) Runner {
return &stdsqlRunner{}
}
type StdSql interface {
Query(string, ...interface{}) (*sql.Rows, error)
QueryRow(string, ...interface{}) *sql.Row
Exec(string, ...interface{}) (sql.Result, error)
}
type stdsqlRunner struct {
StdSql
}
func ( *stdsqlRunner) ( string, ...interface{}) RowScanner {
return .StdSql.QueryRow(, ...)
}
func ( interface{}, BaseRunner) interface{} {
switch r := .(type) {
case StdSqlCtx:
= WrapStdSqlCtx()
case StdSql:
= WrapStdSql()
}
return builder.Set(, "RunWith", )
}
var RunnerNotSet = fmt.Errorf("cannot run; no Runner set (RunWith)")
var RunnerNotQueryRunner = fmt.Errorf("cannot QueryRow; Runner is not a QueryRower")
func ( QueryRower, Sqlizer) RowScanner {
, , := .ToSql()
return &Row{RowScanner: .QueryRow(, ...), err: }
}
func ( Sqlizer) string {
, , := .ToSql()
if != nil {
return fmt.Sprintf("[ToSql error: %s]", )
}
var string
, := .(placeholderDebugger)
if ! {
= "?"
} else {
= .debugPlaceholder()
:= &bytes.Buffer{}
:= 0
for {
:= strings.Index(, )
if == -1 {
break
}
if len([:]) > 1 && [:+2] == "??" { // escape ?? => ?
.WriteString([:])
.WriteString("?")
if len([:]) == 1 {
break
}
= [+2:]
} else {
if +1 > len() {
return fmt.Sprintf(
"[DebugSqlizer error: too many placeholders in %#v for %d args]",
, len())
}
.WriteString([:])
.WriteString()
return .String()
![]() |
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. |