This reverts commit f14c79f170.
Этот коммит содержится в:
Jesse Hallam
2020-04-17 14:26:29 -03:00
коммит произвёл GitHub
родитель be7ee97dd3
Коммит 29fae242e1
628 изменённых файлов: 143991 добавлений и 89603 удалений

18
vendor/github.com/Masterminds/squirrel/.travis.yml сгенерированный поставляемый
Просмотреть файл

@@ -1,9 +1,11 @@
language: go
go:
- 1.8.x
- 1.9.x
- 1.10.x
- 1.11.x
- 1.12.x
- 1.13.x
- tip
services:
- mysql
@@ -15,16 +17,18 @@ services:
# - http://docs.travis-ci.com/user/workers/standard-infrastructure/
sudo: false
install:
- go get -t -tags integration
- go install github.com/mattn/go-sqlite3 # Precompile so test timing is accurate
before_script:
- mysql -e 'CREATE DATABASE squirrel;'
- psql -c 'CREATE DATABASE squirrel;' -U postgres
script:
- go test
- cd integration
- go test -args -driver sqlite3
- go test -args -driver mysql -dataSource travis@/squirrel
- go test -args -driver postgres -dataSource 'postgres://postgres@localhost/squirrel?sslmode=disable'
- go test -tags integration -args -driver sqlite3
- go test -tags integration -args -driver mysql -dataSource travis@/squirrel
- go test -tags integration -args -driver postgres -dataSource 'postgres://postgres@localhost/squirrel?sslmode=disable'
notifications:
irc: "irc.freenode.net#masterminds"

18
vendor/github.com/Masterminds/squirrel/README.md сгенерированный поставляемый
Просмотреть файл

@@ -1,17 +1,21 @@
[![Project Status: Inactive – The project has reached a stable, usable state but is no longer being actively developed; support/maintenance will be provided as time allows.](https://www.repostatus.org/badges/latest/inactive.svg)](https://www.repostatus.org/#inactive)
### Squirrel is "complete".
Bug fixes will still be merged (slowly). Bug reports are welcome, but I will not necessarily respond to them. If another fork (or substantially similar project) actively improves on what Squirrel does, let me know and I may link to it here.
# Squirrel - fluent SQL generator for Go
```go
import "gopkg.in/Masterminds/squirrel.v1"
```
or if you prefer using `master` (which may be arbitrarily ahead of or behind `v1`):
**NOTE:** as of Go 1.6, `go get` correctly clones the Github default branch (which is `v1` in this repo).
```go
import "github.com/Masterminds/squirrel"
```
[![GoDoc](https://godoc.org/github.com/Masterminds/squirrel?status.png)](https://godoc.org/github.com/Masterminds/squirrel)
[![Build Status](https://api.travis-ci.org/Masterminds/squirrel.svg?branch=master)](https://travis-ci.org/Masterminds/squirrel)
[![Build Status](https://travis-ci.org/Masterminds/squirrel.svg?branch=v1)](https://travis-ci.org/Masterminds/squirrel)
_**Note:** This project has moved from `github.com/lann/squirrel` to
`github.com/Masterminds/squirrel`. Lann remains the architect of the
project, but we're helping him curate.
**Squirrel is not an ORM.** For an application of Squirrel, check out
[structable, a table-struct mapper](https://github.com/Masterminds/structable)

29
vendor/github.com/Masterminds/squirrel/delete.go сгенерированный поставляемый
Просмотреть файл

@@ -12,13 +12,13 @@ import (
type deleteData struct {
PlaceholderFormat PlaceholderFormat
RunWith BaseRunner
Prefixes []Sqlizer
Prefixes exprs
From string
WhereParts []Sqlizer
OrderBys []string
Limit string
Offset string
Suffixes []Sqlizer
Suffixes exprs
}
func (d *deleteData) Exec() (sql.Result, error) {
@@ -37,11 +37,7 @@ func (d *deleteData) ToSql() (sqlStr string, args []interface{}, err error) {
sql := &bytes.Buffer{}
if len(d.Prefixes) > 0 {
args, err = appendToSql(d.Prefixes, sql, " ", args)
if err != nil {
return
}
args, _ = d.Prefixes.AppendToSql(sql, " ", args)
sql.WriteString(" ")
}
@@ -73,10 +69,7 @@ func (d *deleteData) ToSql() (sqlStr string, args []interface{}, err error) {
if len(d.Suffixes) > 0 {
sql.WriteString(" ")
args, err = appendToSql(d.Suffixes, sql, " ", args)
if err != nil {
return
}
args, _ = d.Suffixes.AppendToSql(sql, " ", args)
}
sqlStr, err = d.PlaceholderFormat.ReplacePlaceholders(sql.String())
@@ -123,12 +116,7 @@ func (b DeleteBuilder) ToSql() (string, []interface{}, error) {
// Prefix adds an expression to the beginning of the query
func (b DeleteBuilder) Prefix(sql string, args ...interface{}) DeleteBuilder {
return b.PrefixExpr(Expr(sql, args...))
}
// PrefixExpr adds an expression to the very beginning of the query
func (b DeleteBuilder) PrefixExpr(expr Sqlizer) DeleteBuilder {
return builder.Append(b, "Prefixes", expr).(DeleteBuilder)
return builder.Append(b, "Prefixes", Expr(sql, args...)).(DeleteBuilder)
}
// From sets the table to be deleted from.
@@ -160,12 +148,7 @@ func (b DeleteBuilder) Offset(offset uint64) DeleteBuilder {
// Suffix adds an expression to the end of the query
func (b DeleteBuilder) Suffix(sql string, args ...interface{}) DeleteBuilder {
return b.SuffixExpr(Expr(sql, args...))
}
// SuffixExpr adds an expression to the end of the query
func (b DeleteBuilder) SuffixExpr(expr Sqlizer) DeleteBuilder {
return builder.Append(b, "Suffixes", expr).(DeleteBuilder)
return builder.Append(b, "Suffixes", Expr(sql, args...)).(DeleteBuilder)
}
func (b DeleteBuilder) Query() (*sql.Rows, error) {

126
vendor/github.com/Masterminds/squirrel/expr.go сгенерированный поставляемый
Просмотреть файл

@@ -1,9 +1,9 @@
package squirrel
import (
"bytes"
"database/sql/driver"
"fmt"
"io"
"reflect"
"sort"
"strings"
@@ -20,95 +20,35 @@ type expr struct {
args []interface{}
}
// Expr builds an expression from a SQL fragment and arguments.
// Expr builds value expressions for InsertBuilder and UpdateBuilder.
//
// Ex:
// Expr("FROM_UNIXTIME(?)", t)
// .Values(Expr("FROM_UNIXTIME(?)", t))
func Expr(sql string, args ...interface{}) expr {
return expr{sql: sql, args: args}
}
func (e expr) ToSql() (sql string, args []interface{}, err error) {
simple := true
for _, arg := range e.args {
if _, ok := arg.(Sqlizer); ok {
simple = false
}
}
if simple {
return e.sql, e.args, nil
}
buf := &bytes.Buffer{}
ap := e.args
sp := e.sql
var isql string
var iargs []interface{}
for err == nil && len(ap) > 0 && len(sp) > 0 {
i := strings.Index(sp, "?")
if i < 0 {
// no more placeholders
break
}
if len(sp) > i+1 && sp[i+1:i+2] == "?" {
// escaped "??"; append it and step past
buf.WriteString(sp[:i+2])
sp = sp[i+2:]
continue
}
if as, ok := ap[0].(Sqlizer); ok {
// sqlizer argument; expand it and append the result
isql, iargs, err = as.ToSql()
buf.WriteString(sp[:i])
buf.WriteString(isql)
args = append(args, iargs...)
} else {
// normal argument; append it and the placeholder
buf.WriteString(sp[:i+1])
args = append(args, ap[0])
}
// step past the argument and placeholder
ap = ap[1:]
sp = sp[i+1:]
}
// append the remaining sql and arguments
buf.WriteString(sp)
return buf.String(), append(args, ap...), err
return e.sql, e.args, nil
}
type concatExpr []interface{}
type exprs []expr
func (ce concatExpr) ToSql() (sql string, args []interface{}, err error) {
for _, part := range ce {
switch p := part.(type) {
case string:
sql += p
case Sqlizer:
pSql, pArgs, err := p.ToSql()
func (es exprs) AppendToSql(w io.Writer, sep string, args []interface{}) ([]interface{}, error) {
for i, e := range es {
if i > 0 {
_, err := io.WriteString(w, sep)
if err != nil {
return "", nil, err
return nil, err
}
sql += pSql
args = append(args, pArgs...)
default:
return "", nil, fmt.Errorf("%#v is not a string or Sqlizer", part)
}
_, err := io.WriteString(w, e.sql)
if err != nil {
return nil, err
}
args = append(args, e.args...)
}
return
}
// ConcatExpr builds an expression by concatenating strings and other expressions.
//
// Ex:
// name_expr := Expr("CONCAT(?, ' ', ?)", firstName, lastName)
// ConcatExpr("COALESCE(full_name,", name_expr, ")")
func ConcatExpr(parts ...interface{}) concatExpr {
return concatExpr(parts)
return args, nil
}
// aliasExpr helps to alias part of SQL query generated with underlying "expr"
@@ -226,8 +166,16 @@ func (neq NotEq) ToSql() (sql string, args []interface{}, err error) {
// .Where(Like{"name": "%irrel"})
type Like map[string]interface{}
func (lk Like) toSql(opr string) (sql string, args []interface{}, err error) {
var exprs []string
func (lk Like) toSql(opposite bool) (sql string, args []interface{}, err error) {
var (
exprs []string
opr = "LIKE"
)
if opposite {
opr = "NOT LIKE"
}
for key, val := range lk {
expr := ""
@@ -257,7 +205,7 @@ func (lk Like) toSql(opr string) (sql string, args []interface{}, err error) {
}
func (lk Like) ToSql() (sql string, args []interface{}, err error) {
return lk.toSql("LIKE")
return lk.toSql(false)
}
// NotLike is syntactic sugar for use with LIKE conditions.
@@ -266,25 +214,7 @@ func (lk Like) ToSql() (sql string, args []interface{}, err error) {
type NotLike Like
func (nlk NotLike) ToSql() (sql string, args []interface{}, err error) {
return Like(nlk).toSql("NOT LIKE")
}
// ILike is syntactic sugar for use with ILIKE conditions.
// Ex:
// .Where(ILike{"name": "sq%"})
type ILike Like
func (ilk ILike) ToSql() (sql string, args []interface{}, err error) {
return Like(ilk).toSql("ILIKE")
}
// NotILike is syntactic sugar for use with ILIKE conditions.
// Ex:
// .Where(NotILike{"name": "sq%"})
type NotILike Like
func (nilk NotILike) ToSql() (sql string, args []interface{}, err error) {
return Like(nilk).toSql("NOT ILIKE")
return Like(nlk).toSql(true)
}
// Lt is syntactic sugar for use with Where/Having/Set methods.

52
vendor/github.com/Masterminds/squirrel/insert.go сгенерированный поставляемый
Просмотреть файл

@@ -15,13 +15,12 @@ import (
type insertData struct {
PlaceholderFormat PlaceholderFormat
RunWith BaseRunner
Prefixes []Sqlizer
StatementKeyword string
Prefixes exprs
Options []string
Into string
Columns []string
Values [][]interface{}
Suffixes []Sqlizer
Suffixes exprs
Select *SelectBuilder
}
@@ -63,20 +62,11 @@ func (d *insertData) ToSql() (sqlStr string, args []interface{}, err error) {
sql := &bytes.Buffer{}
if len(d.Prefixes) > 0 {
args, err = appendToSql(d.Prefixes, sql, " ", args)
if err != nil {
return
}
args, _ = d.Prefixes.AppendToSql(sql, " ", args)
sql.WriteString(" ")
}
if d.StatementKeyword == "" {
sql.WriteString("INSERT ")
} else {
sql.WriteString(d.StatementKeyword)
sql.WriteString(" ")
}
sql.WriteString("INSERT ")
if len(d.Options) > 0 {
sql.WriteString(strings.Join(d.Options, " "))
@@ -104,10 +94,7 @@ func (d *insertData) ToSql() (sqlStr string, args []interface{}, err error) {
if len(d.Suffixes) > 0 {
sql.WriteString(" ")
args, err = appendToSql(d.Suffixes, sql, " ", args)
if err != nil {
return
}
args, _ = d.Suffixes.AppendToSql(sql, " ", args)
}
sqlStr, err = d.PlaceholderFormat.ReplacePlaceholders(sql.String())
@@ -125,13 +112,10 @@ func (d *insertData) appendValuesToSQL(w io.Writer, args []interface{}) ([]inter
for r, row := range d.Values {
valueStrings := make([]string, len(row))
for v, val := range row {
if vs, ok := val.(Sqlizer); ok {
vsql, vargs, err := vs.ToSql()
if err != nil {
return nil, err
}
valueStrings[v] = vsql
args = append(args, vargs...)
e, isExpr := val.(expr)
if isExpr {
valueStrings[v] = e.sql
args = append(args, e.args...)
} else {
valueStrings[v] = "?"
args = append(args, val)
@@ -218,12 +202,7 @@ func (b InsertBuilder) ToSql() (string, []interface{}, error) {
// Prefix adds an expression to the beginning of the query
func (b InsertBuilder) Prefix(sql string, args ...interface{}) InsertBuilder {
return b.PrefixExpr(Expr(sql, args...))
}
// PrefixExpr adds an expression to the very beginning of the query
func (b InsertBuilder) PrefixExpr(expr Sqlizer) InsertBuilder {
return builder.Append(b, "Prefixes", expr).(InsertBuilder)
return builder.Append(b, "Prefixes", Expr(sql, args...)).(InsertBuilder)
}
// Options adds keyword options before the INTO clause of the query.
@@ -248,12 +227,7 @@ func (b InsertBuilder) Values(values ...interface{}) InsertBuilder {
// Suffix adds an expression to the end of the query
func (b InsertBuilder) Suffix(sql string, args ...interface{}) InsertBuilder {
return b.SuffixExpr(Expr(sql, args...))
}
// SuffixExpr adds an expression to the end of the query
func (b InsertBuilder) SuffixExpr(expr Sqlizer) InsertBuilder {
return builder.Append(b, "Suffixes", expr).(InsertBuilder)
return builder.Append(b, "Suffixes", Expr(sql, args...)).(InsertBuilder)
}
// SetMap set columns and values for insert builder from a map of column name and value
@@ -282,7 +256,3 @@ func (b InsertBuilder) SetMap(clauses map[string]interface{}) InsertBuilder {
func (b InsertBuilder) Select(sb SelectBuilder) InsertBuilder {
return builder.Set(b, "Select", &sb).(InsertBuilder)
}
func (b InsertBuilder) statementKeyword(keyword string) InsertBuilder {
return builder.Set(b, "StatementKeyword", keyword).(InsertBuilder)
}

16
vendor/github.com/Masterminds/squirrel/placeholder.go сгенерированный поставляемый
Просмотреть файл

@@ -14,10 +14,6 @@ type PlaceholderFormat interface {
ReplacePlaceholders(sql string) (string, error)
}
type placeholderDebugger interface {
debugPlaceholder() string
}
var (
// Question is a PlaceholderFormat instance that leaves placeholders as
// question marks.
@@ -38,30 +34,18 @@ func (questionFormat) ReplacePlaceholders(sql string) (string, error) {
return sql, nil
}
func (questionFormat) debugPlaceholder() string {
return "?"
}
type dollarFormat struct{}
func (dollarFormat) ReplacePlaceholders(sql string) (string, error) {
return replacePositionalPlaceholders(sql, "$")
}
func (dollarFormat) debugPlaceholder() string {
return "$"
}
type colonFormat struct{}
func (colonFormat) ReplacePlaceholders(sql string) (string, error) {
return replacePositionalPlaceholders(sql, ":")
}
func (colonFormat) debugPlaceholder() string {
return ":"
}
// Placeholders returns a string with count ? placeholders joined with commas.
func Placeholders(count int) string {
if count < 1 {

59
vendor/github.com/Masterminds/squirrel/select.go сгенерированный поставляемый
Просмотреть файл

@@ -12,7 +12,7 @@ import (
type selectData struct {
PlaceholderFormat PlaceholderFormat
RunWith BaseRunner
Prefixes []Sqlizer
Prefixes exprs
Options []string
Columns []Sqlizer
From Sqlizer
@@ -20,10 +20,10 @@ type selectData struct {
WhereParts []Sqlizer
GroupBys []string
HavingParts []Sqlizer
OrderByParts []Sqlizer
OrderBys []string
Limit string
Offset string
Suffixes []Sqlizer
Suffixes exprs
}
func (d *selectData) Exec() (sql.Result, error) {
@@ -74,11 +74,7 @@ func (d *selectData) toSql() (sqlStr string, args []interface{}, err error) {
sql := &bytes.Buffer{}
if len(d.Prefixes) > 0 {
args, err = appendToSql(d.Prefixes, sql, " ", args)
if err != nil {
return
}
args, _ = d.Prefixes.AppendToSql(sql, " ", args)
sql.WriteString(" ")
}
@@ -133,12 +129,9 @@ func (d *selectData) toSql() (sqlStr string, args []interface{}, err error) {
}
}
if len(d.OrderByParts) > 0 {
if len(d.OrderBys) > 0 {
sql.WriteString(" ORDER BY ")
args, err = appendToSql(d.OrderByParts, sql, ", ", args)
if err != nil {
return
}
sql.WriteString(strings.Join(d.OrderBys, ", "))
}
if len(d.Limit) > 0 {
@@ -153,11 +146,7 @@ func (d *selectData) toSql() (sqlStr string, args []interface{}, err error) {
if len(d.Suffixes) > 0 {
sql.WriteString(" ")
args, err = appendToSql(d.Suffixes, sql, " ", args)
if err != nil {
return
}
args, _ = d.Suffixes.AppendToSql(sql, " ", args)
}
sqlStr = sql.String()
@@ -234,12 +223,7 @@ func (b SelectBuilder) toSqlRaw() (string, []interface{}, error) {
// Prefix adds an expression to the beginning of the query
func (b SelectBuilder) Prefix(sql string, args ...interface{}) SelectBuilder {
return b.PrefixExpr(Expr(sql, args...))
}
// PrefixExpr adds an expression to the very beginning of the query
func (b SelectBuilder) PrefixExpr(expr Sqlizer) SelectBuilder {
return builder.Append(b, "Prefixes", expr).(SelectBuilder)
return builder.Append(b, "Prefixes", Expr(sql, args...)).(SelectBuilder)
}
// Distinct adds a DISTINCT clause to the query.
@@ -254,7 +238,7 @@ func (b SelectBuilder) Options(options ...string) SelectBuilder {
// Columns adds result columns to the query.
func (b SelectBuilder) Columns(columns ...string) SelectBuilder {
parts := make([]interface{}, 0, len(columns))
var parts []interface{}
for _, str := range columns {
parts = append(parts, newPart(str))
}
@@ -276,8 +260,6 @@ func (b SelectBuilder) From(from string) SelectBuilder {
// FromSelect sets a subquery into the FROM clause of the query.
func (b SelectBuilder) FromSelect(from SelectBuilder, alias string) SelectBuilder {
// Prevent misnumbered parameters in nested selects (#183).
from = from.PlaceholderFormat(Question)
return builder.Set(b, "From", Alias(from, alias)).(SelectBuilder)
}
@@ -340,18 +322,9 @@ func (b SelectBuilder) Having(pred interface{}, rest ...interface{}) SelectBuild
return builder.Append(b, "HavingParts", newWherePart(pred, rest...)).(SelectBuilder)
}
// OrderByClause adds ORDER BY clause to the query.
func (b SelectBuilder) OrderByClause(pred interface{}, args ...interface{}) SelectBuilder {
return builder.Append(b, "OrderByParts", newPart(pred, args...)).(SelectBuilder)
}
// OrderBy adds ORDER BY expressions to the query.
func (b SelectBuilder) OrderBy(orderBys ...string) SelectBuilder {
for _, orderBy := range orderBys {
b = b.OrderByClause(orderBy)
}
return b
return builder.Extend(b, "OrderBys", orderBys).(SelectBuilder)
}
// Limit sets a LIMIT clause on the query.
@@ -369,17 +342,7 @@ func (b SelectBuilder) Offset(offset uint64) SelectBuilder {
return builder.Set(b, "Offset", fmt.Sprintf("%d", offset)).(SelectBuilder)
}
// RemoveOffset removes OFFSET clause.
func (b SelectBuilder) RemoveOffset() SelectBuilder {
return builder.Delete(b, "Offset").(SelectBuilder)
}
// Suffix adds an expression to the end of the query
func (b SelectBuilder) Suffix(sql string, args ...interface{}) SelectBuilder {
return b.SuffixExpr(Expr(sql, args...))
}
// SuffixExpr adds an expression to the end of the query
func (b SelectBuilder) SuffixExpr(expr Sqlizer) SelectBuilder {
return builder.Append(b, "Suffixes", expr).(SelectBuilder)
return builder.Append(b, "Suffixes", Expr(sql, args...)).(SelectBuilder)
}

43
vendor/github.com/Masterminds/squirrel/squirrel.go сгенерированный поставляемый
Просмотреть файл

@@ -5,6 +5,7 @@ package squirrel
import (
"bytes"
"context"
"database/sql"
"fmt"
"strings"
@@ -60,34 +61,31 @@ type Runner interface {
QueryRower
}
// WrapStdSql wraps a type implementing the standard SQL interface with methods that
// squirrel expects.
func WrapStdSql(stdSql StdSql) Runner {
return &stdsqlRunner{stdSql}
}
// StdSql encompasses the standard methods of the *sql.DB type, and other types that
// wrap these methods.
type StdSql interface {
type stdsql interface {
Query(string, ...interface{}) (*sql.Rows, error)
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
QueryRow(string, ...interface{}) *sql.Row
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
Exec(string, ...interface{}) (sql.Result, error)
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
}
type stdsqlRunner struct {
StdSql
stdsql
}
func (r *stdsqlRunner) QueryRow(query string, args ...interface{}) RowScanner {
return r.StdSql.QueryRow(query, args...)
return r.stdsql.QueryRow(query, args...)
}
func setRunWith(b interface{}, runner BaseRunner) interface{} {
switch r := runner.(type) {
case StdSqlCtx:
runner = WrapStdSqlCtx(r)
case StdSql:
runner = WrapStdSql(r)
func setRunWith(b interface{}, baseRunner BaseRunner) interface{} {
var runner Runner
switch r := baseRunner.(type) {
case Runner:
runner = r
case stdsql:
runner = &stdsqlRunner{r}
}
return builder.Set(b, "RunWith", runner)
}
@@ -137,18 +135,11 @@ func DebugSqlizer(s Sqlizer) string {
return fmt.Sprintf("[ToSql error: %s]", err)
}
var placeholder string
downCast, ok := s.(placeholderDebugger)
if !ok {
placeholder = "?"
} else {
placeholder = downCast.debugPlaceholder()
}
// TODO: dedupe this with placeholder.go
buf := &bytes.Buffer{}
i := 0
for {
p := strings.Index(sql, placeholder)
p := strings.Index(sql, "?")
if p == -1 {
break
}
@@ -167,7 +158,6 @@ func DebugSqlizer(s Sqlizer) string {
}
buf.WriteString(sql[:p])
fmt.Fprintf(buf, "'%v'", args[i])
// advance our sql string "cursor" beyond the arg we placed
sql = sql[p+1:]
i++
}
@@ -177,7 +167,6 @@ func DebugSqlizer(s Sqlizer) string {
"[DebugSqlizer error: not enough placeholders in %#v for %d args]",
sql, len(args))
}
// "append" any remaning sql that won't need interpolating
buf.WriteString(sql)
return buf.String()
}

36
vendor/github.com/Masterminds/squirrel/squirrel_ctx.go сгенерированный поставляемый
Просмотреть файл

@@ -32,40 +32,8 @@ type QueryRowerContext interface {
QueryRowContext(ctx context.Context, query string, args ...interface{}) RowScanner
}
// RunnerContext groups the Runner interface, along with the Contect versions of each of
// its methods
type RunnerContext interface {
Runner
QueryerContext
QueryRowerContext
ExecerContext
}
// WrapStdSqlCtx wraps a type implementing the standard SQL interface plus the context
// versions of the methods with methods that squirrel expects.
func WrapStdSqlCtx(stdSqlCtx StdSqlCtx) RunnerContext {
return &stdsqlCtxRunner{stdSqlCtx}
}
// StdSqlCtx encompasses the standard methods of the *sql.DB type, along with the Context
// versions of those methods, and other types that wrap these methods.
type StdSqlCtx interface {
StdSql
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
}
type stdsqlCtxRunner struct {
StdSqlCtx
}
func (r *stdsqlCtxRunner) QueryRow(query string, args ...interface{}) RowScanner {
return r.StdSqlCtx.QueryRow(query, args...)
}
func (r *stdsqlCtxRunner) QueryRowContext(ctx context.Context, query string, args ...interface{}) RowScanner {
return r.StdSqlCtx.QueryRowContext(ctx, query, args...)
func (r *stdsqlRunner) QueryRowContext(ctx context.Context, query string, args ...interface{}) RowScanner {
return r.stdsql.QueryRowContext(ctx, query, args...)
}
// ExecContextWith ExecContexts the SQL returned by s with db.

14
vendor/github.com/Masterminds/squirrel/statement.go сгенерированный поставляемый
Просмотреть файл

@@ -15,12 +15,6 @@ func (b StatementBuilderType) Insert(into string) InsertBuilder {
return InsertBuilder(b).Into(into)
}
// Replace returns a InsertBuilder for this StatementBuilderType with the
// statement keyword set to "REPLACE".
func (b StatementBuilderType) Replace(into string) InsertBuilder {
return InsertBuilder(b).statementKeyword("REPLACE").Into(into)
}
// Update returns a UpdateBuilder for this StatementBuilderType.
func (b StatementBuilderType) Update(table string) UpdateBuilder {
return UpdateBuilder(b).Table(table)
@@ -58,14 +52,6 @@ func Insert(into string) InsertBuilder {
return StatementBuilder.Insert(into)
}
// Replace returns a new InsertBuilder with the statement keyword set to
// "REPLACE" and with the given table name.
//
// See InsertBuilder.Into.
func Replace(into string) InsertBuilder {
return StatementBuilder.Replace(into)
}
// Update returns a new UpdateBuilder with the given table name.
//
// See UpdateBuilder.Table.

50
vendor/github.com/Masterminds/squirrel/stmtcacher.go сгенерированный поставляемый
Просмотреть файл

@@ -2,7 +2,6 @@ package squirrel
import (
"database/sql"
"fmt"
"sync"
)
@@ -21,25 +20,17 @@ type DBProxy interface {
Preparer
}
// NOTE: NewStmtCache is defined in stmtcacher_ctx.go (Go >= 1.8) or stmtcacher_noctx.go (Go < 1.8).
// NOTE: NewStmtCacher is defined in stmtcacher_ctx.go (Go >= 1.8) or stmtcacher_noctx.go (Go < 1.8).
// StmtCache wraps and delegates down to a Preparer type
//
// It also automatically prepares all statements sent to the underlying Preparer calls
// for Exec, Query and QueryRow and caches the returns *sql.Stmt using the provided
// query as the key. So that it can be automatically re-used.
type StmtCache struct {
type stmtCacher struct {
prep Preparer
cache map[string]*sql.Stmt
mu sync.Mutex
}
// Prepare delegates down to the underlying Preparer and caches the result
// using the provided query as a key
func (sc *StmtCache) Prepare(query string) (*sql.Stmt, error) {
func (sc *stmtCacher) Prepare(query string) (*sql.Stmt, error) {
sc.mu.Lock()
defer sc.mu.Unlock()
stmt, ok := sc.cache[query]
if ok {
return stmt, nil
@@ -51,8 +42,7 @@ func (sc *StmtCache) Prepare(query string) (*sql.Stmt, error) {
return stmt, err
}
// Exec delegates down to the underlying Preparer using a prepared statement
func (sc *StmtCache) Exec(query string, args ...interface{}) (res sql.Result, err error) {
func (sc *stmtCacher) Exec(query string, args ...interface{}) (res sql.Result, err error) {
stmt, err := sc.Prepare(query)
if err != nil {
return
@@ -60,8 +50,7 @@ func (sc *StmtCache) Exec(query string, args ...interface{}) (res sql.Result, er
return stmt.Exec(args...)
}
// Query delegates down to the underlying Preparer using a prepared statement
func (sc *StmtCache) Query(query string, args ...interface{}) (rows *sql.Rows, err error) {
func (sc *stmtCacher) Query(query string, args ...interface{}) (rows *sql.Rows, err error) {
stmt, err := sc.Prepare(query)
if err != nil {
return
@@ -69,8 +58,7 @@ func (sc *StmtCache) Query(query string, args ...interface{}) (rows *sql.Rows, e
return stmt.Query(args...)
}
// QueryRow delegates down to the underlying Preparer using a prepared statement
func (sc *StmtCache) QueryRow(query string, args ...interface{}) RowScanner {
func (sc *stmtCacher) QueryRow(query string, args ...interface{}) RowScanner {
stmt, err := sc.Prepare(query)
if err != nil {
return &Row{err: err}
@@ -78,30 +66,6 @@ func (sc *StmtCache) QueryRow(query string, args ...interface{}) RowScanner {
return stmt.QueryRow(args...)
}
// Clear removes and closes all the currently cached prepared statements
func (sc *StmtCache) Clear() (err error) {
sc.mu.Lock()
defer sc.mu.Unlock()
for key, stmt := range sc.cache {
delete(sc.cache, key)
if stmt == nil {
continue
}
if cerr := stmt.Close(); cerr != nil {
err = cerr
}
}
if err != nil {
return fmt.Errorf("one or more Stmt.Close failed; last error: %v", err)
}
return
}
type DBProxyBeginner interface {
DBProxy
Begin() (*sql.Tx, error)
@@ -113,7 +77,7 @@ type stmtCacheProxy struct {
}
func NewStmtCacheProxy(db *sql.DB) DBProxyBeginner {
return &stmtCacheProxy{DBProxy: NewStmtCache(db), db: db}
return &stmtCacheProxy{DBProxy: NewStmtCacher(db), db: db}
}
func (sp *stmtCacheProxy) Begin() (*sql.Tx, error) {

24
vendor/github.com/Masterminds/squirrel/stmtcacher_ctx.go сгенерированный поставляемый
Просмотреть файл

@@ -24,23 +24,14 @@ type DBProxyContext interface {
PreparerContext
}
// NewStmtCache returns a *StmtCache wrapping a PreparerContext that caches Prepared Stmts.
// NewStmtCacher returns a DBProxy wrapping prep that caches Prepared Stmts.
//
// Stmts are cached based on the string value of their queries.
func NewStmtCache(prep PreparerContext) *StmtCache {
return &StmtCache{prep: prep, cache: make(map[string]*sql.Stmt)}
}
// NewStmtCacher is deprecated
//
// Use NewStmtCache instead
func NewStmtCacher(prep PreparerContext) DBProxyContext {
return NewStmtCache(prep)
return &stmtCacher{prep: prep, cache: make(map[string]*sql.Stmt)}
}
// PrepareContext delegates down to the underlying PreparerContext and caches the result
// using the provided query as a key
func (sc *StmtCache) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) {
func (sc *stmtCacher) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) {
ctxPrep, ok := sc.prep.(PreparerContext)
if !ok {
return nil, NoContextSupport
@@ -58,8 +49,7 @@ func (sc *StmtCache) PrepareContext(ctx context.Context, query string) (*sql.Stm
return stmt, err
}
// ExecContext delegates down to the underlying PreparerContext using a prepared statement
func (sc *StmtCache) ExecContext(ctx context.Context, query string, args ...interface{}) (res sql.Result, err error) {
func (sc *stmtCacher) ExecContext(ctx context.Context, query string, args ...interface{}) (res sql.Result, err error) {
stmt, err := sc.PrepareContext(ctx, query)
if err != nil {
return
@@ -67,8 +57,7 @@ func (sc *StmtCache) ExecContext(ctx context.Context, query string, args ...inte
return stmt.ExecContext(ctx, args...)
}
// QueryContext delegates down to the underlying PreparerContext using a prepared statement
func (sc *StmtCache) QueryContext(ctx context.Context, query string, args ...interface{}) (rows *sql.Rows, err error) {
func (sc *stmtCacher) QueryContext(ctx context.Context, query string, args ...interface{}) (rows *sql.Rows, err error) {
stmt, err := sc.PrepareContext(ctx, query)
if err != nil {
return
@@ -76,8 +65,7 @@ func (sc *StmtCache) QueryContext(ctx context.Context, query string, args ...int
return stmt.QueryContext(ctx, args...)
}
// QueryRowContext delegates down to the underlying PreparerContext using a prepared statement
func (sc *StmtCache) QueryRowContext(ctx context.Context, query string, args ...interface{}) RowScanner {
func (sc *stmtCacher) QueryRowContext(ctx context.Context, query string, args ...interface{}) RowScanner {
stmt, err := sc.PrepareContext(ctx, query)
if err != nil {
return &Row{err: err}

9
vendor/github.com/Masterminds/squirrel/stmtcacher_noctx.go сгенерированный поставляемый
Просмотреть файл

@@ -9,13 +9,6 @@ import (
// NewStmtCacher returns a DBProxy wrapping prep that caches Prepared Stmts.
//
// Stmts are cached based on the string value of their queries.
func NewStmtCache(prep Preparer) *StmtCache {
return &StmtCacher{prep: prep, cache: make(map[string]*sql.Stmt)}
}
// NewStmtCacher is deprecated
//
// Use NewStmtCache instead
func NewStmtCacher(prep Preparer) DBProxy {
return NewStmtCache(prep)
return &stmtCacher{prep: prep, cache: make(map[string]*sql.Stmt)}
}

40
vendor/github.com/Masterminds/squirrel/update.go сгенерированный поставляемый
Просмотреть файл

@@ -13,14 +13,14 @@ import (
type updateData struct {
PlaceholderFormat PlaceholderFormat
RunWith BaseRunner
Prefixes []Sqlizer
Prefixes exprs
Table string
SetClauses []setClause
WhereParts []Sqlizer
OrderBys []string
Limit string
Offset string
Suffixes []Sqlizer
Suffixes exprs
}
type setClause struct {
@@ -66,11 +66,7 @@ func (d *updateData) ToSql() (sqlStr string, args []interface{}, err error) {
sql := &bytes.Buffer{}
if len(d.Prefixes) > 0 {
args, err = appendToSql(d.Prefixes, sql, " ", args)
if err != nil {
return
}
args, _ = d.Prefixes.AppendToSql(sql, " ", args)
sql.WriteString(" ")
}
@@ -81,13 +77,10 @@ func (d *updateData) ToSql() (sqlStr string, args []interface{}, err error) {
setSqls := make([]string, len(d.SetClauses))
for i, setClause := range d.SetClauses {
var valSql string
if vs, ok := setClause.value.(Sqlizer); ok {
vsql, vargs, err := vs.ToSql()
if err != nil {
return "", nil, err
}
valSql = vsql
args = append(args, vargs...)
e, isExpr := setClause.value.(expr)
if isExpr {
valSql = e.sql
args = append(args, e.args...)
} else {
valSql = "?"
args = append(args, setClause.value)
@@ -121,10 +114,7 @@ func (d *updateData) ToSql() (sqlStr string, args []interface{}, err error) {
if len(d.Suffixes) > 0 {
sql.WriteString(" ")
args, err = appendToSql(d.Suffixes, sql, " ", args)
if err != nil {
return
}
args, _ = d.Suffixes.AppendToSql(sql, " ", args)
}
sqlStr, err = d.PlaceholderFormat.ReplacePlaceholders(sql.String())
@@ -185,12 +175,7 @@ func (b UpdateBuilder) ToSql() (string, []interface{}, error) {
// Prefix adds an expression to the beginning of the query
func (b UpdateBuilder) Prefix(sql string, args ...interface{}) UpdateBuilder {
return b.PrefixExpr(Expr(sql, args...))
}
// PrefixExpr adds an expression to the very beginning of the query
func (b UpdateBuilder) PrefixExpr(expr Sqlizer) UpdateBuilder {
return builder.Append(b, "Prefixes", expr).(UpdateBuilder)
return builder.Append(b, "Prefixes", Expr(sql, args...)).(UpdateBuilder)
}
// Table sets the table to be updated.
@@ -243,10 +228,5 @@ func (b UpdateBuilder) Offset(offset uint64) UpdateBuilder {
// Suffix adds an expression to the end of the query
func (b UpdateBuilder) Suffix(sql string, args ...interface{}) UpdateBuilder {
return b.SuffixExpr(Expr(sql, args...))
}
// SuffixExpr adds an expression to the end of the query
func (b UpdateBuilder) SuffixExpr(expr Sqlizer) UpdateBuilder {
return builder.Append(b, "Suffixes", expr).(UpdateBuilder)
return builder.Append(b, "Suffixes", Expr(sql, args...)).(UpdateBuilder)
}