MM-24312: Fix Dependency updates (#14391)

Automatic Merge
Этот коммит содержится в:
Agniva De Sarker
2020-04-30 02:36:09 +05:30
коммит произвёл GitHub
родитель a3cf490a4d
Коммит 03a55367d9
899 изменённых файлов: 135672 добавлений и 158738 удалений

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

@@ -1,11 +1,9 @@
language: go
go:
- 1.8.x
- 1.9.x
- 1.10.x
- 1.11.x
- tip
- 1.12.x
- 1.13.x
services:
- mysql
@@ -17,18 +15,16 @@ 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 -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'
- 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'
notifications:
irc: "irc.freenode.net#masterminds"

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

@@ -1,21 +1,17 @@
[![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://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.
[![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)
**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 exprs
Prefixes []Sqlizer
From string
WhereParts []Sqlizer
OrderBys []string
Limit string
Offset string
Suffixes exprs
Suffixes []Sqlizer
}
func (d *deleteData) Exec() (sql.Result, error) {
@@ -37,7 +37,11 @@ func (d *deleteData) ToSql() (sqlStr string, args []interface{}, err error) {
sql := &bytes.Buffer{}
if len(d.Prefixes) > 0 {
args, _ = d.Prefixes.AppendToSql(sql, " ", args)
args, err = appendToSql(d.Prefixes, sql, " ", args)
if err != nil {
return
}
sql.WriteString(" ")
}
@@ -69,7 +73,10 @@ func (d *deleteData) ToSql() (sqlStr string, args []interface{}, err error) {
if len(d.Suffixes) > 0 {
sql.WriteString(" ")
args, _ = d.Suffixes.AppendToSql(sql, " ", args)
args, err = appendToSql(d.Suffixes, sql, " ", args)
if err != nil {
return
}
}
sqlStr, err = d.PlaceholderFormat.ReplacePlaceholders(sql.String())
@@ -116,7 +123,12 @@ 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 builder.Append(b, "Prefixes", Expr(sql, args...)).(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)
}
// From sets the table to be deleted from.
@@ -148,7 +160,12 @@ 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 builder.Append(b, "Suffixes", Expr(sql, args...)).(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)
}
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,35 +20,95 @@ type expr struct {
args []interface{}
}
// Expr builds value expressions for InsertBuilder and UpdateBuilder.
// Expr builds an expression from a SQL fragment and arguments.
//
// Ex:
// .Values(Expr("FROM_UNIXTIME(?)", t))
// 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) {
return e.sql, e.args, nil
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
}
type exprs []expr
type concatExpr []interface{}
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)
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()
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 args, nil
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)
}
// aliasExpr helps to alias part of SQL query generated with underlying "expr"
@@ -166,16 +226,8 @@ func (neq NotEq) ToSql() (sql string, args []interface{}, err error) {
// .Where(Like{"name": "%irrel"})
type Like map[string]interface{}
func (lk Like) toSql(opposite bool) (sql string, args []interface{}, err error) {
var (
exprs []string
opr = "LIKE"
)
if opposite {
opr = "NOT LIKE"
}
func (lk Like) toSql(opr string) (sql string, args []interface{}, err error) {
var exprs []string
for key, val := range lk {
expr := ""
@@ -205,7 +257,7 @@ func (lk Like) toSql(opposite bool) (sql string, args []interface{}, err error)
}
func (lk Like) ToSql() (sql string, args []interface{}, err error) {
return lk.toSql(false)
return lk.toSql("LIKE")
}
// NotLike is syntactic sugar for use with LIKE conditions.
@@ -214,7 +266,25 @@ 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(true)
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")
}
// Lt is syntactic sugar for use with Where/Having/Set methods.

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

@@ -15,12 +15,13 @@ import (
type insertData struct {
PlaceholderFormat PlaceholderFormat
RunWith BaseRunner
Prefixes exprs
Prefixes []Sqlizer
StatementKeyword string
Options []string
Into string
Columns []string
Values [][]interface{}
Suffixes exprs
Suffixes []Sqlizer
Select *SelectBuilder
}
@@ -62,11 +63,20 @@ func (d *insertData) ToSql() (sqlStr string, args []interface{}, err error) {
sql := &bytes.Buffer{}
if len(d.Prefixes) > 0 {
args, _ = d.Prefixes.AppendToSql(sql, " ", args)
args, err = appendToSql(d.Prefixes, sql, " ", args)
if err != nil {
return
}
sql.WriteString(" ")
}
sql.WriteString("INSERT ")
if d.StatementKeyword == "" {
sql.WriteString("INSERT ")
} else {
sql.WriteString(d.StatementKeyword)
sql.WriteString(" ")
}
if len(d.Options) > 0 {
sql.WriteString(strings.Join(d.Options, " "))
@@ -94,7 +104,10 @@ func (d *insertData) ToSql() (sqlStr string, args []interface{}, err error) {
if len(d.Suffixes) > 0 {
sql.WriteString(" ")
args, _ = d.Suffixes.AppendToSql(sql, " ", args)
args, err = appendToSql(d.Suffixes, sql, " ", args)
if err != nil {
return
}
}
sqlStr, err = d.PlaceholderFormat.ReplacePlaceholders(sql.String())
@@ -112,10 +125,13 @@ 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 {
e, isExpr := val.(expr)
if isExpr {
valueStrings[v] = e.sql
args = append(args, e.args...)
if vs, ok := val.(Sqlizer); ok {
vsql, vargs, err := vs.ToSql()
if err != nil {
return nil, err
}
valueStrings[v] = vsql
args = append(args, vargs...)
} else {
valueStrings[v] = "?"
args = append(args, val)
@@ -202,7 +218,12 @@ 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 builder.Append(b, "Prefixes", Expr(sql, args...)).(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)
}
// Options adds keyword options before the INTO clause of the query.
@@ -227,7 +248,12 @@ 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 builder.Append(b, "Suffixes", Expr(sql, args...)).(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)
}
// SetMap set columns and values for insert builder from a map of column name and value
@@ -256,3 +282,7 @@ 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,6 +14,10 @@ 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.
@@ -34,18 +38,30 @@ 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 exprs
Prefixes []Sqlizer
Options []string
Columns []Sqlizer
From Sqlizer
@@ -20,10 +20,10 @@ type selectData struct {
WhereParts []Sqlizer
GroupBys []string
HavingParts []Sqlizer
OrderBys []string
OrderByParts []Sqlizer
Limit string
Offset string
Suffixes exprs
Suffixes []Sqlizer
}
func (d *selectData) Exec() (sql.Result, error) {
@@ -74,7 +74,11 @@ func (d *selectData) toSql() (sqlStr string, args []interface{}, err error) {
sql := &bytes.Buffer{}
if len(d.Prefixes) > 0 {
args, _ = d.Prefixes.AppendToSql(sql, " ", args)
args, err = appendToSql(d.Prefixes, sql, " ", args)
if err != nil {
return
}
sql.WriteString(" ")
}
@@ -129,9 +133,12 @@ func (d *selectData) toSql() (sqlStr string, args []interface{}, err error) {
}
}
if len(d.OrderBys) > 0 {
if len(d.OrderByParts) > 0 {
sql.WriteString(" ORDER BY ")
sql.WriteString(strings.Join(d.OrderBys, ", "))
args, err = appendToSql(d.OrderByParts, sql, ", ", args)
if err != nil {
return
}
}
if len(d.Limit) > 0 {
@@ -146,7 +153,11 @@ func (d *selectData) toSql() (sqlStr string, args []interface{}, err error) {
if len(d.Suffixes) > 0 {
sql.WriteString(" ")
args, _ = d.Suffixes.AppendToSql(sql, " ", args)
args, err = appendToSql(d.Suffixes, sql, " ", args)
if err != nil {
return
}
}
sqlStr = sql.String()
@@ -223,7 +234,12 @@ 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 builder.Append(b, "Prefixes", Expr(sql, args...)).(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)
}
// Distinct adds a DISTINCT clause to the query.
@@ -238,7 +254,7 @@ func (b SelectBuilder) Options(options ...string) SelectBuilder {
// Columns adds result columns to the query.
func (b SelectBuilder) Columns(columns ...string) SelectBuilder {
var parts []interface{}
parts := make([]interface{}, 0, len(columns))
for _, str := range columns {
parts = append(parts, newPart(str))
}
@@ -260,6 +276,8 @@ 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)
}
@@ -322,9 +340,18 @@ 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 {
return builder.Extend(b, "OrderBys", orderBys).(SelectBuilder)
for _, orderBy := range orderBys {
b = b.OrderByClause(orderBy)
}
return b
}
// Limit sets a LIMIT clause on the query.
@@ -342,7 +369,17 @@ 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 builder.Append(b, "Suffixes", Expr(sql, args...)).(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)
}

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

@@ -5,7 +5,6 @@ package squirrel
import (
"bytes"
"context"
"database/sql"
"fmt"
"strings"
@@ -61,31 +60,34 @@ type Runner interface {
QueryRower
}
type stdsql interface {
// 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 {
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{}, baseRunner BaseRunner) interface{} {
var runner Runner
switch r := baseRunner.(type) {
case Runner:
runner = r
case stdsql:
runner = &stdsqlRunner{r}
func setRunWith(b interface{}, runner BaseRunner) interface{} {
switch r := runner.(type) {
case StdSqlCtx:
runner = WrapStdSqlCtx(r)
case StdSql:
runner = WrapStdSql(r)
}
return builder.Set(b, "RunWith", runner)
}
@@ -135,11 +137,18 @@ 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, "?")
p := strings.Index(sql, placeholder)
if p == -1 {
break
}
@@ -158,6 +167,7 @@ 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++
}
@@ -167,6 +177,7 @@ 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,8 +32,40 @@ type QueryRowerContext interface {
QueryRowContext(ctx context.Context, query string, args ...interface{}) RowScanner
}
func (r *stdsqlRunner) QueryRowContext(ctx context.Context, query string, args ...interface{}) RowScanner {
return r.stdsql.QueryRowContext(ctx, query, args...)
// 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...)
}
// ExecContextWith ExecContexts the SQL returned by s with db.

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

@@ -15,6 +15,12 @@ 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)
@@ -52,6 +58,14 @@ 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,6 +2,7 @@ package squirrel
import (
"database/sql"
"fmt"
"sync"
)
@@ -20,17 +21,25 @@ type DBProxy interface {
Preparer
}
// NOTE: NewStmtCacher is defined in stmtcacher_ctx.go (Go >= 1.8) or stmtcacher_noctx.go (Go < 1.8).
// NOTE: NewStmtCache is defined in stmtcacher_ctx.go (Go >= 1.8) or stmtcacher_noctx.go (Go < 1.8).
type stmtCacher struct {
// 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 {
prep Preparer
cache map[string]*sql.Stmt
mu sync.Mutex
}
func (sc *stmtCacher) Prepare(query string) (*sql.Stmt, error) {
// 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) {
sc.mu.Lock()
defer sc.mu.Unlock()
stmt, ok := sc.cache[query]
if ok {
return stmt, nil
@@ -42,7 +51,8 @@ func (sc *stmtCacher) Prepare(query string) (*sql.Stmt, error) {
return stmt, err
}
func (sc *stmtCacher) Exec(query string, args ...interface{}) (res sql.Result, err error) {
// Exec delegates down to the underlying Preparer using a prepared statement
func (sc *StmtCache) Exec(query string, args ...interface{}) (res sql.Result, err error) {
stmt, err := sc.Prepare(query)
if err != nil {
return
@@ -50,7 +60,8 @@ func (sc *stmtCacher) Exec(query string, args ...interface{}) (res sql.Result, e
return stmt.Exec(args...)
}
func (sc *stmtCacher) Query(query string, args ...interface{}) (rows *sql.Rows, err error) {
// Query delegates down to the underlying Preparer using a prepared statement
func (sc *StmtCache) Query(query string, args ...interface{}) (rows *sql.Rows, err error) {
stmt, err := sc.Prepare(query)
if err != nil {
return
@@ -58,7 +69,8 @@ func (sc *stmtCacher) Query(query string, args ...interface{}) (rows *sql.Rows,
return stmt.Query(args...)
}
func (sc *stmtCacher) QueryRow(query string, args ...interface{}) RowScanner {
// QueryRow delegates down to the underlying Preparer using a prepared statement
func (sc *StmtCache) QueryRow(query string, args ...interface{}) RowScanner {
stmt, err := sc.Prepare(query)
if err != nil {
return &Row{err: err}
@@ -66,6 +78,30 @@ func (sc *stmtCacher) 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)
@@ -77,7 +113,7 @@ type stmtCacheProxy struct {
}
func NewStmtCacheProxy(db *sql.DB) DBProxyBeginner {
return &stmtCacheProxy{DBProxy: NewStmtCacher(db), db: db}
return &stmtCacheProxy{DBProxy: NewStmtCache(db), db: db}
}
func (sp *stmtCacheProxy) Begin() (*sql.Tx, error) {

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

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

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

@@ -9,6 +9,13 @@ import (
// NewStmtCacher returns a DBProxy wrapping prep that caches Prepared Stmts.
//
// Stmts are cached based on the string value of their queries.
func NewStmtCacher(prep Preparer) DBProxy {
return &stmtCacher{prep: prep, cache: make(map[string]*sql.Stmt)}
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)
}

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

@@ -13,14 +13,14 @@ import (
type updateData struct {
PlaceholderFormat PlaceholderFormat
RunWith BaseRunner
Prefixes exprs
Prefixes []Sqlizer
Table string
SetClauses []setClause
WhereParts []Sqlizer
OrderBys []string
Limit string
Offset string
Suffixes exprs
Suffixes []Sqlizer
}
type setClause struct {
@@ -66,7 +66,11 @@ func (d *updateData) ToSql() (sqlStr string, args []interface{}, err error) {
sql := &bytes.Buffer{}
if len(d.Prefixes) > 0 {
args, _ = d.Prefixes.AppendToSql(sql, " ", args)
args, err = appendToSql(d.Prefixes, sql, " ", args)
if err != nil {
return
}
sql.WriteString(" ")
}
@@ -77,10 +81,13 @@ 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
e, isExpr := setClause.value.(expr)
if isExpr {
valSql = e.sql
args = append(args, e.args...)
if vs, ok := setClause.value.(Sqlizer); ok {
vsql, vargs, err := vs.ToSql()
if err != nil {
return "", nil, err
}
valSql = vsql
args = append(args, vargs...)
} else {
valSql = "?"
args = append(args, setClause.value)
@@ -114,7 +121,10 @@ func (d *updateData) ToSql() (sqlStr string, args []interface{}, err error) {
if len(d.Suffixes) > 0 {
sql.WriteString(" ")
args, _ = d.Suffixes.AppendToSql(sql, " ", args)
args, err = appendToSql(d.Suffixes, sql, " ", args)
if err != nil {
return
}
}
sqlStr, err = d.PlaceholderFormat.ReplacePlaceholders(sql.String())
@@ -175,7 +185,12 @@ 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 builder.Append(b, "Prefixes", Expr(sql, args...)).(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)
}
// Table sets the table to be updated.
@@ -228,5 +243,10 @@ 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 builder.Append(b, "Suffixes", Expr(sql, args...)).(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)
}