mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	Added all required dependencies
This commit is contained in:
		
							
								
								
									
										27
									
								
								vendor/github.com/go-xorm/builder/LICENSE
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								vendor/github.com/go-xorm/builder/LICENSE
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| Copyright (c) 2016 The Xorm Authors | ||||
| All rights reserved. | ||||
|  | ||||
| Redistribution and use in source and binary forms, with or without | ||||
| modification, are permitted provided that the following conditions are met: | ||||
|  | ||||
| * Redistributions of source code must retain the above copyright notice, this | ||||
|   list of conditions and the following disclaimer. | ||||
|  | ||||
| * Redistributions in binary form must reproduce the above copyright notice, | ||||
|   this list of conditions and the following disclaimer in the documentation | ||||
|   and/or other materials provided with the distribution. | ||||
|  | ||||
| * Neither the name of the {organization} nor the names of its | ||||
|   contributors may be used to endorse or promote products derived from | ||||
|   this software without specific prior written permission. | ||||
|  | ||||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||||
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||||
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||||
| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||||
| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||||
| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||||
| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||||
| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||||
| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||||
| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
							
								
								
									
										173
									
								
								vendor/github.com/go-xorm/builder/README.md
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										173
									
								
								vendor/github.com/go-xorm/builder/README.md
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,173 @@ | ||||
| # SQL builder | ||||
|  | ||||
| Package builder is a simple and powerful sql builder for Go. | ||||
|  | ||||
| Make sure you have installed Go 1.1+ and then: | ||||
|  | ||||
|     go get github.com/go-xorm/builder | ||||
|  | ||||
| # Insert | ||||
|  | ||||
| ```Go | ||||
| sql, args, err := Insert(Eq{"c": 1, "d": 2}).Into("table1").ToSQL() | ||||
| ``` | ||||
|  | ||||
| # Select | ||||
|  | ||||
| ```Go | ||||
| sql, args, err := Select("c, d").From("table1").Where(Eq{"a": 1}).ToSQL() | ||||
|  | ||||
| sql, args, err = Select("c, d").From("table1").LeftJoin("table2", Eq{"table1.id": 1}.And(Lt{"table2.id": 3})). | ||||
| 		RightJoin("table3", "table2.id = table3.tid").Where(Eq{"a": 1}).ToSQL() | ||||
| ``` | ||||
|  | ||||
| # Update | ||||
|  | ||||
| ```Go | ||||
| sql, args, err := Update(Eq{"a": 2}).From("table1").Where(Eq{"a": 1}).ToSQL() | ||||
| ``` | ||||
|  | ||||
| # Delete | ||||
|  | ||||
| ```Go | ||||
| sql, args, err := Delete(Eq{"a": 1}).From("table1").ToSQL() | ||||
| ``` | ||||
|  | ||||
| # Conditions | ||||
|  | ||||
| * `Eq` is a redefine of a map, you can give one or more conditions to `Eq` | ||||
|  | ||||
| ```Go | ||||
| import . "github.com/go-xorm/builder" | ||||
|  | ||||
| sql, args, _ := ToSQL(Eq{"a":1}) | ||||
| // a=? [1] | ||||
| sql, args, _ := ToSQL(Eq{"b":"c"}.And(Eq{"c": 0})) | ||||
| // b=? AND c=? ["c", 0] | ||||
| sql, args, _ := ToSQL(Eq{"b":"c", "c":0}) | ||||
| // b=? AND c=? ["c", 0] | ||||
| sql, args, _ := ToSQL(Eq{"b":"c"}.Or(Eq{"b":"d"})) | ||||
| // b=? OR b=? ["c", "d"] | ||||
| sql, args, _ := ToSQL(Eq{"b": []string{"c", "d"}}) | ||||
| // b IN (?,?) ["c", "d"] | ||||
| sql, args, _ := ToSQL(Eq{"b": 1, "c":[]int{2, 3}}) | ||||
| // b=? AND c IN (?,?) [1, 2, 3] | ||||
| ``` | ||||
|  | ||||
| * `Neq` is the same to `Eq` | ||||
|  | ||||
| ```Go | ||||
| import . "github.com/go-xorm/builder" | ||||
|  | ||||
| sql, args, _ := ToSQL(Neq{"a":1}) | ||||
| // a<>? [1] | ||||
| sql, args, _ := ToSQL(Neq{"b":"c"}.And(Neq{"c": 0})) | ||||
| // b<>? AND c<>? ["c", 0] | ||||
| sql, args, _ := ToSQL(Neq{"b":"c", "c":0}) | ||||
| // b<>? AND c<>? ["c", 0] | ||||
| sql, args, _ := ToSQL(Neq{"b":"c"}.Or(Neq{"b":"d"})) | ||||
| // b<>? OR b<>? ["c", "d"] | ||||
| sql, args, _ := ToSQL(Neq{"b": []string{"c", "d"}}) | ||||
| // b NOT IN (?,?) ["c", "d"] | ||||
| sql, args, _ := ToSQL(Neq{"b": 1, "c":[]int{2, 3}}) | ||||
| // b<>? AND c NOT IN (?,?) [1, 2, 3] | ||||
| ``` | ||||
|  | ||||
| * `Gt`, `Gte`, `Lt`, `Lte` | ||||
|  | ||||
| ```Go | ||||
| import . "github.com/go-xorm/builder" | ||||
|  | ||||
| sql, args, _ := ToSQL(Gt{"a", 1}.And(Gte{"b", 2})) | ||||
| // a>? AND b>=? [1, 2] | ||||
| sql, args, _ := ToSQL(Lt{"a", 1}.Or(Lte{"b", 2})) | ||||
| // a<? OR b<=? [1, 2] | ||||
| ``` | ||||
|  | ||||
| * `Like` | ||||
|  | ||||
| ```Go | ||||
| import . "github.com/go-xorm/builder" | ||||
|  | ||||
| sql, args, _ := ToSQL(Like{"a", "c"}) | ||||
| // a LIKE ? [%c%] | ||||
| ``` | ||||
|  | ||||
| * `Expr` you can customerize your sql with `Expr` | ||||
|  | ||||
| ```Go | ||||
| import . "github.com/go-xorm/builder" | ||||
|  | ||||
| sql, args, _ := ToSQL(Expr("a = ? ", 1)) | ||||
| // a = ? [1] | ||||
| sql, args, _ := ToSQL(Eq{"a": Expr("select id from table where c = ?", 1)}) | ||||
| // a=(select id from table where c = ?) [1] | ||||
| ``` | ||||
|  | ||||
| * `In` and `NotIn` | ||||
|  | ||||
| ```Go | ||||
| import . "github.com/go-xorm/builder" | ||||
|  | ||||
| sql, args, _ := ToSQL(In("a", 1, 2, 3)) | ||||
| // a IN (?,?,?) [1,2,3] | ||||
| sql, args, _ := ToSQL(In("a", []int{1, 2, 3})) | ||||
| // a IN (?,?,?) [1,2,3] | ||||
| sql, args, _ := ToSQL(In("a", Expr("select id from b where c = ?", 1)))) | ||||
| // a IN (select id from b where c = ?) [1] | ||||
| ``` | ||||
|  | ||||
| * `IsNull` and `NotNull` | ||||
|  | ||||
| ```Go | ||||
| import . "github.com/go-xorm/builder" | ||||
|  | ||||
| sql, args, _ := ToSQL(IsNull{"a"}) | ||||
| // a IS NULL [] | ||||
| sql, args, _ := ToSQL(NotNull{"b"}) | ||||
| 	// b IS NOT NULL [] | ||||
| ``` | ||||
|  | ||||
| * `And(conds ...Cond)`, And can connect one or more condtions via And | ||||
|  | ||||
| ```Go | ||||
| import . "github.com/go-xorm/builder" | ||||
|  | ||||
| sql, args, _ := ToSQL(And(Eq{"a":1}, Like{"b", "c"}, Neq{"d", 2})) | ||||
| // a=? AND b LIKE ? AND d<>? [1, %c%, 2] | ||||
| ``` | ||||
|  | ||||
| * `Or(conds ...Cond)`, Or can connect one or more conditions via Or | ||||
|  | ||||
| ```Go | ||||
| import . "github.com/go-xorm/builder" | ||||
|  | ||||
| sql, args, _ := ToSQL(Or(Eq{"a":1}, Like{"b", "c"}, Neq{"d", 2})) | ||||
| // a=? OR b LIKE ? OR d<>? [1, %c%, 2] | ||||
| sql, args, _ := ToSQL(Or(Eq{"a":1}, And(Like{"b", "c"}, Neq{"d", 2}))) | ||||
| // a=? OR (b LIKE ? AND d<>?) [1, %c%, 2] | ||||
| ``` | ||||
|  | ||||
| * `Between` | ||||
|  | ||||
| ```Go | ||||
| import . "github.com/go-xorm/builder" | ||||
|  | ||||
| sql, args, _ := ToSQL(Between{"a", 1, 2}) | ||||
| // a BETWEEN 1 AND 2 | ||||
| ``` | ||||
|  | ||||
| * Define yourself conditions | ||||
|  | ||||
| Since `Cond` is an interface. | ||||
|  | ||||
| ```Go | ||||
| type Cond interface { | ||||
| 	WriteTo(Writer) error | ||||
| 	And(...Cond) Cond | ||||
| 	Or(...Cond) Cond | ||||
| 	IsValid() bool | ||||
| } | ||||
| ``` | ||||
|  | ||||
| You can define yourself conditions and compose with other `Cond`. | ||||
							
								
								
									
										165
									
								
								vendor/github.com/go-xorm/builder/builder.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										165
									
								
								vendor/github.com/go-xorm/builder/builder.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,165 @@ | ||||
| package builder | ||||
|  | ||||
| type optype byte | ||||
|  | ||||
| const ( | ||||
| 	condType   optype = iota // only conditions | ||||
| 	selectType               // select | ||||
| 	insertType               // insert | ||||
| 	updateType               // update | ||||
| 	deleteType               // delete | ||||
| ) | ||||
|  | ||||
| type join struct { | ||||
| 	joinType  string | ||||
| 	joinTable string | ||||
| 	joinCond  Cond | ||||
| } | ||||
|  | ||||
| type Builder struct { | ||||
| 	optype | ||||
| 	tableName string | ||||
| 	cond      Cond | ||||
| 	selects   []string | ||||
| 	joins     []join | ||||
| 	inserts   Eq | ||||
| 	updates   []Eq | ||||
| } | ||||
|  | ||||
| func Select(cols ...string) *Builder { | ||||
| 	builder := &Builder{cond: NewCond()} | ||||
| 	return builder.Select(cols...) | ||||
| } | ||||
|  | ||||
| func Insert(eq Eq) *Builder { | ||||
| 	builder := &Builder{cond: NewCond()} | ||||
| 	return builder.Insert(eq) | ||||
| } | ||||
|  | ||||
| func Update(updates ...Eq) *Builder { | ||||
| 	builder := &Builder{cond: NewCond()} | ||||
| 	return builder.Update(updates...) | ||||
| } | ||||
|  | ||||
| func Delete(conds ...Cond) *Builder { | ||||
| 	builder := &Builder{cond: NewCond()} | ||||
| 	return builder.Delete(conds...) | ||||
| } | ||||
|  | ||||
| func (b *Builder) Where(cond Cond) *Builder { | ||||
| 	b.cond = b.cond.And(cond) | ||||
| 	return b | ||||
| } | ||||
|  | ||||
| func (b *Builder) From(tableName string) *Builder { | ||||
| 	b.tableName = tableName | ||||
| 	return b | ||||
| } | ||||
|  | ||||
| func (b *Builder) Into(tableName string) *Builder { | ||||
| 	b.tableName = tableName | ||||
| 	return b | ||||
| } | ||||
|  | ||||
| func (b *Builder) Join(joinType, joinTable string, joinCond interface{}) *Builder { | ||||
| 	switch joinCond.(type) { | ||||
| 	case Cond: | ||||
| 		b.joins = append(b.joins, join{joinType, joinTable, joinCond.(Cond)}) | ||||
| 	case string: | ||||
| 		b.joins = append(b.joins, join{joinType, joinTable, Expr(joinCond.(string))}) | ||||
| 	} | ||||
|  | ||||
| 	return b | ||||
| } | ||||
|  | ||||
| func (b *Builder) InnerJoin(joinTable string, joinCond interface{}) *Builder { | ||||
| 	return b.Join("INNER", joinTable, joinCond) | ||||
| } | ||||
|  | ||||
| func (b *Builder) LeftJoin(joinTable string, joinCond interface{}) *Builder { | ||||
| 	return b.Join("LEFT", joinTable, joinCond) | ||||
| } | ||||
|  | ||||
| func (b *Builder) RightJoin(joinTable string, joinCond interface{}) *Builder { | ||||
| 	return b.Join("RIGHT", joinTable, joinCond) | ||||
| } | ||||
|  | ||||
| func (b *Builder) CrossJoin(joinTable string, joinCond interface{}) *Builder { | ||||
| 	return b.Join("CROSS", joinTable, joinCond) | ||||
| } | ||||
|  | ||||
| func (b *Builder) FullJoin(joinTable string, joinCond interface{}) *Builder { | ||||
| 	return b.Join("FULL", joinTable, joinCond) | ||||
| } | ||||
|  | ||||
| func (b *Builder) Select(cols ...string) *Builder { | ||||
| 	b.selects = cols | ||||
| 	b.optype = selectType | ||||
| 	return b | ||||
| } | ||||
|  | ||||
| func (b *Builder) And(cond Cond) *Builder { | ||||
| 	b.cond = And(b.cond, cond) | ||||
| 	return b | ||||
| } | ||||
|  | ||||
| func (b *Builder) Or(cond Cond) *Builder { | ||||
| 	b.cond = Or(b.cond, cond) | ||||
| 	return b | ||||
| } | ||||
|  | ||||
| func (b *Builder) Insert(eq Eq) *Builder { | ||||
| 	b.inserts = eq | ||||
| 	b.optype = insertType | ||||
| 	return b | ||||
| } | ||||
|  | ||||
| func (b *Builder) Update(updates ...Eq) *Builder { | ||||
| 	b.updates = updates | ||||
| 	b.optype = updateType | ||||
| 	return b | ||||
| } | ||||
|  | ||||
| func (b *Builder) Delete(conds ...Cond) *Builder { | ||||
| 	b.cond = b.cond.And(conds...) | ||||
| 	b.optype = deleteType | ||||
| 	return b | ||||
| } | ||||
|  | ||||
| func (b *Builder) WriteTo(w Writer) error { | ||||
| 	switch b.optype { | ||||
| 	case condType: | ||||
| 		return b.cond.WriteTo(w) | ||||
| 	case selectType: | ||||
| 		return b.selectWriteTo(w) | ||||
| 	case insertType: | ||||
| 		return b.insertWriteTo(w) | ||||
| 	case updateType: | ||||
| 		return b.updateWriteTo(w) | ||||
| 	case deleteType: | ||||
| 		return b.deleteWriteTo(w) | ||||
| 	} | ||||
|  | ||||
| 	return ErrNotSupportType | ||||
| } | ||||
|  | ||||
| // ToSQL convert a builder to SQL and args | ||||
| func (b *Builder) ToSQL() (string, []interface{}, error) { | ||||
| 	w := NewWriter() | ||||
| 	if err := b.WriteTo(w); err != nil { | ||||
| 		return "", nil, err | ||||
| 	} | ||||
|  | ||||
| 	return w.writer.String(), w.args, nil | ||||
| } | ||||
|  | ||||
| // ToSQL convert a builder or condtions to SQL and args | ||||
| func ToSQL(cond interface{}) (string, []interface{}, error) { | ||||
| 	switch cond.(type) { | ||||
| 	case Cond: | ||||
| 		return condToSQL(cond.(Cond)) | ||||
| 	case *Builder: | ||||
| 		return cond.(*Builder).ToSQL() | ||||
| 	} | ||||
| 	return "", nil, ErrNotSupportType | ||||
| } | ||||
							
								
								
									
										18
									
								
								vendor/github.com/go-xorm/builder/builder_delete.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								vendor/github.com/go-xorm/builder/builder_delete.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| package builder | ||||
|  | ||||
| import ( | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| ) | ||||
|  | ||||
| func (b *Builder) deleteWriteTo(w Writer) error { | ||||
| 	if len(b.tableName) <= 0 { | ||||
| 		return errors.New("no table indicated") | ||||
| 	} | ||||
|  | ||||
| 	if _, err := fmt.Fprintf(w, "DELETE FROM %s WHERE ", b.tableName); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	return b.cond.WriteTo(w) | ||||
| } | ||||
							
								
								
									
										60
									
								
								vendor/github.com/go-xorm/builder/builder_insert.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								vendor/github.com/go-xorm/builder/builder_insert.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,60 @@ | ||||
| package builder | ||||
|  | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| ) | ||||
|  | ||||
| func (b *Builder) insertWriteTo(w Writer) error { | ||||
| 	if len(b.tableName) <= 0 { | ||||
| 		return errors.New("no table indicated") | ||||
| 	} | ||||
| 	if len(b.inserts) <= 0 { | ||||
| 		return errors.New("no column to be update") | ||||
| 	} | ||||
|  | ||||
| 	if _, err := fmt.Fprintf(w, "INSERT INTO %s (", b.tableName); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	var args = make([]interface{}, 0) | ||||
| 	var bs []byte | ||||
| 	var valBuffer = bytes.NewBuffer(bs) | ||||
| 	var i = 0 | ||||
| 	for col, value := range b.inserts { | ||||
| 		fmt.Fprint(w, col) | ||||
| 		if e, ok := value.(expr); ok { | ||||
| 			fmt.Fprint(valBuffer, e.sql) | ||||
| 			args = append(args, e.args...) | ||||
| 		} else { | ||||
| 			fmt.Fprint(valBuffer, "?") | ||||
| 			args = append(args, value) | ||||
| 		} | ||||
|  | ||||
| 		if i != len(b.inserts)-1 { | ||||
| 			if _, err := fmt.Fprint(w, ","); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 			if _, err := fmt.Fprint(valBuffer, ","); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 		} | ||||
| 		i = i + 1 | ||||
| 	} | ||||
|  | ||||
| 	if _, err := fmt.Fprint(w, ") Values ("); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	if _, err := w.Write(valBuffer.Bytes()); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	if _, err := fmt.Fprint(w, ")"); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	w.Append(args...) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
							
								
								
									
										49
									
								
								vendor/github.com/go-xorm/builder/builder_select.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								vendor/github.com/go-xorm/builder/builder_select.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,49 @@ | ||||
| package builder | ||||
|  | ||||
| import ( | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| ) | ||||
|  | ||||
| func (b *Builder) selectWriteTo(w Writer) error { | ||||
| 	if len(b.tableName) <= 0 { | ||||
| 		return errors.New("no table indicated") | ||||
| 	} | ||||
|  | ||||
| 	if _, err := fmt.Fprint(w, "SELECT "); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	if len(b.selects) > 0 { | ||||
| 		for i, s := range b.selects { | ||||
| 			if _, err := fmt.Fprint(w, s); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 			if i != len(b.selects)-1 { | ||||
| 				if _, err := fmt.Fprint(w, ","); err != nil { | ||||
| 					return err | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} else { | ||||
| 		if _, err := fmt.Fprint(w, "*"); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if _, err := fmt.Fprintf(w, " FROM %s", b.tableName); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	for _, v := range b.joins { | ||||
| 		fmt.Fprintf(w, " %s JOIN %s ON ", v.joinType, v.joinTable) | ||||
| 		if err := v.joinCond.WriteTo(w); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if _, err := fmt.Fprint(w, " WHERE "); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	return b.cond.WriteTo(w) | ||||
| } | ||||
							
								
								
									
										37
									
								
								vendor/github.com/go-xorm/builder/builder_update.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								vendor/github.com/go-xorm/builder/builder_update.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| package builder | ||||
|  | ||||
| import ( | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| ) | ||||
|  | ||||
| func (b *Builder) updateWriteTo(w Writer) error { | ||||
| 	if len(b.tableName) <= 0 { | ||||
| 		return errors.New("no table indicated") | ||||
| 	} | ||||
| 	if len(b.updates) <= 0 { | ||||
| 		return errors.New("no column to be update") | ||||
| 	} | ||||
|  | ||||
| 	if _, err := fmt.Fprintf(w, "UPDATE %s SET ", b.tableName); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	for i, s := range b.updates { | ||||
| 		if err := s.opWriteTo(",", w); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
|  | ||||
| 		if i != len(b.updates)-1 { | ||||
| 			if _, err := fmt.Fprint(w, ","); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if _, err := fmt.Fprint(w, " WHERE "); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	return b.cond.WriteTo(w) | ||||
| } | ||||
							
								
								
									
										74
									
								
								vendor/github.com/go-xorm/builder/cond.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								vendor/github.com/go-xorm/builder/cond.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,74 @@ | ||||
| package builder | ||||
|  | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"io" | ||||
| ) | ||||
|  | ||||
| type Writer interface { | ||||
| 	io.Writer | ||||
| 	Append(...interface{}) | ||||
| } | ||||
|  | ||||
| type stringWriter struct { | ||||
| 	writer *bytes.Buffer | ||||
| 	buffer []byte | ||||
| 	args   []interface{} | ||||
| } | ||||
|  | ||||
| func NewWriter() *stringWriter { | ||||
| 	w := &stringWriter{} | ||||
| 	w.writer = bytes.NewBuffer(w.buffer) | ||||
| 	return w | ||||
| } | ||||
|  | ||||
| func (s *stringWriter) Write(buf []byte) (int, error) { | ||||
| 	return s.writer.Write(buf) | ||||
| } | ||||
|  | ||||
| func (s *stringWriter) Append(args ...interface{}) { | ||||
| 	s.args = append(s.args, args...) | ||||
| } | ||||
|  | ||||
| type Cond interface { | ||||
| 	WriteTo(Writer) error | ||||
| 	And(...Cond) Cond | ||||
| 	Or(...Cond) Cond | ||||
| 	IsValid() bool | ||||
| } | ||||
|  | ||||
| type condEmpty struct{} | ||||
|  | ||||
| var _ Cond = condEmpty{} | ||||
|  | ||||
| func NewCond() Cond { | ||||
| 	return condEmpty{} | ||||
| } | ||||
|  | ||||
| func (condEmpty) WriteTo(w Writer) error { | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (condEmpty) And(conds ...Cond) Cond { | ||||
| 	return And(conds...) | ||||
| } | ||||
|  | ||||
| func (condEmpty) Or(conds ...Cond) Cond { | ||||
| 	return Or(conds...) | ||||
| } | ||||
|  | ||||
| func (condEmpty) IsValid() bool { | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| func condToSQL(cond Cond) (string, []interface{}, error) { | ||||
| 	if cond == nil || !cond.IsValid() { | ||||
| 		return "", nil, nil | ||||
| 	} | ||||
|  | ||||
| 	w := NewWriter() | ||||
| 	if err := cond.WriteTo(w); err != nil { | ||||
| 		return "", nil, err | ||||
| 	} | ||||
| 	return w.writer.String(), w.args, nil | ||||
| } | ||||
							
								
								
									
										54
									
								
								vendor/github.com/go-xorm/builder/cond_and.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								vendor/github.com/go-xorm/builder/cond_and.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,54 @@ | ||||
| package builder | ||||
|  | ||||
| import "fmt" | ||||
|  | ||||
| type condAnd []Cond | ||||
|  | ||||
| var _ Cond = condAnd{} | ||||
|  | ||||
| func And(conds ...Cond) Cond { | ||||
| 	var result = make(condAnd, 0, len(conds)) | ||||
| 	for _, cond := range conds { | ||||
| 		if cond == nil || !cond.IsValid() { | ||||
| 			continue | ||||
| 		} | ||||
| 		result = append(result, cond) | ||||
| 	} | ||||
| 	return result | ||||
| } | ||||
|  | ||||
| func (and condAnd) WriteTo(w Writer) error { | ||||
| 	for i, cond := range and { | ||||
| 		_, isOr := cond.(condOr) | ||||
| 		if isOr { | ||||
| 			fmt.Fprint(w, "(") | ||||
| 		} | ||||
|  | ||||
| 		err := cond.WriteTo(w) | ||||
| 		if err != nil { | ||||
| 			return err | ||||
| 		} | ||||
|  | ||||
| 		if isOr { | ||||
| 			fmt.Fprint(w, ")") | ||||
| 		} | ||||
|  | ||||
| 		if i != len(and)-1 { | ||||
| 			fmt.Fprint(w, " AND ") | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (and condAnd) And(conds ...Cond) Cond { | ||||
| 	return And(and, And(conds...)) | ||||
| } | ||||
|  | ||||
| func (and condAnd) Or(conds ...Cond) Cond { | ||||
| 	return Or(and, Or(conds...)) | ||||
| } | ||||
|  | ||||
| func (and condAnd) IsValid() bool { | ||||
| 	return len(and) > 0 | ||||
| } | ||||
							
								
								
									
										32
									
								
								vendor/github.com/go-xorm/builder/cond_between.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								vendor/github.com/go-xorm/builder/cond_between.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | ||||
| package builder | ||||
|  | ||||
| import "fmt" | ||||
|  | ||||
| // Between | ||||
| type Between struct { | ||||
| 	Col     string | ||||
| 	LessVal interface{} | ||||
| 	MoreVal interface{} | ||||
| } | ||||
|  | ||||
| var _ Cond = Between{} | ||||
|  | ||||
| func (between Between) WriteTo(w Writer) error { | ||||
| 	if _, err := fmt.Fprintf(w, "%s BETWEEN ? AND ?", between.Col); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	w.Append(between.LessVal, between.MoreVal) | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (between Between) And(conds ...Cond) Cond { | ||||
| 	return And(between, And(conds...)) | ||||
| } | ||||
|  | ||||
| func (between Between) Or(conds ...Cond) Cond { | ||||
| 	return Or(between, Or(conds...)) | ||||
| } | ||||
|  | ||||
| func (between Between) IsValid() bool { | ||||
| 	return len(between.Col) > 0 | ||||
| } | ||||
							
								
								
									
										134
									
								
								vendor/github.com/go-xorm/builder/cond_compare.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										134
									
								
								vendor/github.com/go-xorm/builder/cond_compare.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,134 @@ | ||||
| package builder | ||||
|  | ||||
| import "fmt" | ||||
|  | ||||
| // WriteMap | ||||
| func WriteMap(w Writer, data map[string]interface{}, op string) error { | ||||
| 	var args = make([]interface{}, 0, len(data)) | ||||
| 	var i = 0 | ||||
| 	for k, v := range data { | ||||
| 		switch v.(type) { | ||||
| 		case expr: | ||||
| 			if _, err := fmt.Fprintf(w, "%s%s(", k, op); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
|  | ||||
| 			if err := v.(expr).WriteTo(w); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
|  | ||||
| 			if _, err := fmt.Fprintf(w, ")"); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 		case *Builder: | ||||
| 			if _, err := fmt.Fprintf(w, "%s%s(", k, op); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
|  | ||||
| 			if err := v.(*Builder).WriteTo(w); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
|  | ||||
| 			if _, err := fmt.Fprintf(w, ")"); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 		default: | ||||
| 			if _, err := fmt.Fprintf(w, "%s%s?", k, op); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 			args = append(args, v) | ||||
| 		} | ||||
| 		if i != len(data)-1 { | ||||
| 			if _, err := fmt.Fprint(w, " AND "); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 		} | ||||
| 		i = i + 1 | ||||
| 	} | ||||
| 	w.Append(args...) | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Lt | ||||
| type Lt map[string]interface{} | ||||
|  | ||||
| var _ Cond = Lt{} | ||||
|  | ||||
| func (lt Lt) WriteTo(w Writer) error { | ||||
| 	return WriteMap(w, lt, "<") | ||||
| } | ||||
|  | ||||
| func (lt Lt) And(conds ...Cond) Cond { | ||||
| 	return condAnd{lt, And(conds...)} | ||||
| } | ||||
|  | ||||
| func (lt Lt) Or(conds ...Cond) Cond { | ||||
| 	return condOr{lt, Or(conds...)} | ||||
| } | ||||
|  | ||||
| func (lt Lt) IsValid() bool { | ||||
| 	return len(lt) > 0 | ||||
| } | ||||
|  | ||||
| // Lte | ||||
| type Lte map[string]interface{} | ||||
|  | ||||
| var _ Cond = Lte{} | ||||
|  | ||||
| func (lte Lte) WriteTo(w Writer) error { | ||||
| 	return WriteMap(w, lte, "<=") | ||||
| } | ||||
|  | ||||
| func (lte Lte) And(conds ...Cond) Cond { | ||||
| 	return And(lte, And(conds...)) | ||||
| } | ||||
|  | ||||
| func (lte Lte) Or(conds ...Cond) Cond { | ||||
| 	return Or(lte, Or(conds...)) | ||||
| } | ||||
|  | ||||
| func (lte Lte) IsValid() bool { | ||||
| 	return len(lte) > 0 | ||||
| } | ||||
|  | ||||
| // Gt | ||||
| type Gt map[string]interface{} | ||||
|  | ||||
| var _ Cond = Gt{} | ||||
|  | ||||
| func (gt Gt) WriteTo(w Writer) error { | ||||
| 	return WriteMap(w, gt, ">") | ||||
| } | ||||
|  | ||||
| func (gt Gt) And(conds ...Cond) Cond { | ||||
| 	return And(gt, And(conds...)) | ||||
| } | ||||
|  | ||||
| func (gt Gt) Or(conds ...Cond) Cond { | ||||
| 	return Or(gt, Or(conds...)) | ||||
| } | ||||
|  | ||||
| func (gt Gt) IsValid() bool { | ||||
| 	return len(gt) > 0 | ||||
| } | ||||
|  | ||||
| // Gte | ||||
| type Gte map[string]interface{} | ||||
|  | ||||
| var _ Cond = Gte{} | ||||
|  | ||||
| func (gte Gte) WriteTo(w Writer) error { | ||||
| 	return WriteMap(w, gte, ">=") | ||||
| } | ||||
|  | ||||
| func (gte Gte) And(conds ...Cond) Cond { | ||||
| 	return And(gte, And(conds...)) | ||||
| } | ||||
|  | ||||
| func (gte Gte) Or(conds ...Cond) Cond { | ||||
| 	return Or(gte, Or(conds...)) | ||||
| } | ||||
|  | ||||
| func (gte Gte) IsValid() bool { | ||||
| 	return len(gte) > 0 | ||||
| } | ||||
							
								
								
									
										85
									
								
								vendor/github.com/go-xorm/builder/cond_eq.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										85
									
								
								vendor/github.com/go-xorm/builder/cond_eq.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,85 @@ | ||||
| package builder | ||||
|  | ||||
| import "fmt" | ||||
|  | ||||
| type Incr int | ||||
|  | ||||
| type Decr int | ||||
|  | ||||
| type Eq map[string]interface{} | ||||
|  | ||||
| var _ Cond = Eq{} | ||||
|  | ||||
| func (eq Eq) opWriteTo(op string, w Writer) error { | ||||
| 	var i = 0 | ||||
| 	for k, v := range eq { | ||||
| 		switch v.(type) { | ||||
| 		case []int, []int64, []string, []int32, []int16, []int8, []uint, []uint64, []uint32, []uint16, []interface{}: | ||||
| 			if err := In(k, v).WriteTo(w); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 		case expr: | ||||
| 			if _, err := fmt.Fprintf(w, "%s=(", k); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
|  | ||||
| 			if err := v.(expr).WriteTo(w); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
|  | ||||
| 			if _, err := fmt.Fprintf(w, ")"); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 		case *Builder: | ||||
| 			if _, err := fmt.Fprintf(w, "%s=(", k); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
|  | ||||
| 			if err := v.(*Builder).WriteTo(w); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
|  | ||||
| 			if _, err := fmt.Fprintf(w, ")"); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 		case Incr: | ||||
| 			if _, err := fmt.Fprintf(w, "%s=%s+?", k, k); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 			w.Append(int(v.(Incr))) | ||||
| 		case Decr: | ||||
| 			if _, err := fmt.Fprintf(w, "%s=%s-?", k, k); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 			w.Append(int(v.(Decr))) | ||||
| 		default: | ||||
| 			if _, err := fmt.Fprintf(w, "%s=?", k); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 			w.Append(v) | ||||
| 		} | ||||
| 		if i != len(eq)-1 { | ||||
| 			if _, err := fmt.Fprint(w, op); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 		} | ||||
| 		i = i + 1 | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (eq Eq) WriteTo(w Writer) error { | ||||
| 	return eq.opWriteTo(" AND ", w) | ||||
| } | ||||
|  | ||||
| func (eq Eq) And(conds ...Cond) Cond { | ||||
| 	return And(eq, And(conds...)) | ||||
| } | ||||
|  | ||||
| func (eq Eq) Or(conds ...Cond) Cond { | ||||
| 	return Or(eq, Or(conds...)) | ||||
| } | ||||
|  | ||||
| func (eq Eq) IsValid() bool { | ||||
| 	return len(eq) > 0 | ||||
| } | ||||
							
								
								
									
										34
									
								
								vendor/github.com/go-xorm/builder/cond_expr.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								vendor/github.com/go-xorm/builder/cond_expr.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | ||||
| package builder | ||||
|  | ||||
| import "fmt" | ||||
|  | ||||
| type expr struct { | ||||
| 	sql  string | ||||
| 	args []interface{} | ||||
| } | ||||
|  | ||||
| var _ Cond = expr{} | ||||
|  | ||||
| func Expr(sql string, args ...interface{}) Cond { | ||||
| 	return expr{sql, args} | ||||
| } | ||||
|  | ||||
| func (expr expr) WriteTo(w Writer) error { | ||||
| 	if _, err := fmt.Fprint(w, expr.sql); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	w.Append(expr.args...) | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (expr expr) And(conds ...Cond) Cond { | ||||
| 	return And(expr, And(conds...)) | ||||
| } | ||||
|  | ||||
| func (expr expr) Or(conds ...Cond) Cond { | ||||
| 	return Or(expr, Or(conds...)) | ||||
| } | ||||
|  | ||||
| func (expr expr) IsValid() bool { | ||||
| 	return len(expr.sql) > 0 | ||||
| } | ||||
							
								
								
									
										212
									
								
								vendor/github.com/go-xorm/builder/cond_in.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										212
									
								
								vendor/github.com/go-xorm/builder/cond_in.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,212 @@ | ||||
| package builder | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"strings" | ||||
| ) | ||||
|  | ||||
| type condIn struct { | ||||
| 	col  string | ||||
| 	vals []interface{} | ||||
| } | ||||
|  | ||||
| var _ Cond = condIn{} | ||||
|  | ||||
| func In(col string, values ...interface{}) Cond { | ||||
| 	return condIn{col, values} | ||||
| } | ||||
|  | ||||
| func (condIn condIn) WriteTo(w Writer) error { | ||||
| 	if len(condIn.vals) <= 0 { | ||||
| 		return ErrNoInConditions | ||||
| 	} | ||||
|  | ||||
| 	switch condIn.vals[0].(type) { | ||||
| 	case []int8: | ||||
| 		vals := condIn.vals[0].([]int8) | ||||
| 		if len(vals) <= 0 { | ||||
| 			return ErrNoInConditions | ||||
| 		} | ||||
| 		questionMark := strings.Repeat("?,", len(vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		for _, val := range vals { | ||||
| 			w.Append(val) | ||||
| 		} | ||||
| 	case []int16: | ||||
| 		vals := condIn.vals[0].([]int16) | ||||
| 		if len(vals) <= 0 { | ||||
| 			return ErrNoInConditions | ||||
| 		} | ||||
| 		questionMark := strings.Repeat("?,", len(vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		for _, val := range vals { | ||||
| 			w.Append(val) | ||||
| 		} | ||||
| 	case []int: | ||||
| 		vals := condIn.vals[0].([]int) | ||||
| 		if len(vals) <= 0 { | ||||
| 			return ErrNoInConditions | ||||
| 		} | ||||
| 		questionMark := strings.Repeat("?,", len(vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		for _, val := range vals { | ||||
| 			w.Append(val) | ||||
| 		} | ||||
| 	case []int32: | ||||
| 		vals := condIn.vals[0].([]int32) | ||||
| 		if len(vals) <= 0 { | ||||
| 			return ErrNoInConditions | ||||
| 		} | ||||
| 		questionMark := strings.Repeat("?,", len(vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		for _, val := range vals { | ||||
| 			w.Append(val) | ||||
| 		} | ||||
| 	case []int64: | ||||
| 		vals := condIn.vals[0].([]int64) | ||||
| 		if len(vals) <= 0 { | ||||
| 			return ErrNoInConditions | ||||
| 		} | ||||
| 		questionMark := strings.Repeat("?,", len(vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		for _, val := range vals { | ||||
| 			w.Append(val) | ||||
| 		} | ||||
| 	case []uint8: | ||||
| 		vals := condIn.vals[0].([]uint8) | ||||
| 		if len(vals) <= 0 { | ||||
| 			return ErrNoInConditions | ||||
| 		} | ||||
| 		questionMark := strings.Repeat("?,", len(vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		for _, val := range vals { | ||||
| 			w.Append(val) | ||||
| 		} | ||||
| 	case []uint16: | ||||
| 		vals := condIn.vals[0].([]uint16) | ||||
| 		if len(vals) <= 0 { | ||||
| 			return ErrNoInConditions | ||||
| 		} | ||||
| 		questionMark := strings.Repeat("?,", len(vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		for _, val := range vals { | ||||
| 			w.Append(val) | ||||
| 		} | ||||
| 	case []uint: | ||||
| 		vals := condIn.vals[0].([]uint) | ||||
| 		if len(vals) <= 0 { | ||||
| 			return ErrNoInConditions | ||||
| 		} | ||||
| 		questionMark := strings.Repeat("?,", len(vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		for _, val := range vals { | ||||
| 			w.Append(val) | ||||
| 		} | ||||
| 	case []uint32: | ||||
| 		vals := condIn.vals[0].([]uint32) | ||||
| 		if len(vals) <= 0 { | ||||
| 			return ErrNoInConditions | ||||
| 		} | ||||
| 		questionMark := strings.Repeat("?,", len(vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		for _, val := range vals { | ||||
| 			w.Append(val) | ||||
| 		} | ||||
| 	case []uint64: | ||||
| 		vals := condIn.vals[0].([]uint64) | ||||
| 		if len(vals) <= 0 { | ||||
| 			return ErrNoInConditions | ||||
| 		} | ||||
| 		questionMark := strings.Repeat("?,", len(vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		for _, val := range vals { | ||||
| 			w.Append(val) | ||||
| 		} | ||||
| 	case []string: | ||||
| 		vals := condIn.vals[0].([]string) | ||||
| 		if len(vals) <= 0 { | ||||
| 			return ErrNoInConditions | ||||
| 		} | ||||
| 		questionMark := strings.Repeat("?,", len(vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		for _, val := range vals { | ||||
| 			w.Append(val) | ||||
| 		} | ||||
| 	case []interface{}: | ||||
| 		vals := condIn.vals[0].([]interface{}) | ||||
| 		if len(vals) <= 0 { | ||||
| 			return ErrNoInConditions | ||||
| 		} | ||||
| 		questionMark := strings.Repeat("?,", len(vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		w.Append(vals...) | ||||
| 	case expr: | ||||
| 		val := condIn.vals[0].(expr) | ||||
| 		if _, err := fmt.Fprintf(w, "%s IN (", condIn.col); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		if err := val.WriteTo(w); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		if _, err := fmt.Fprintf(w, ")"); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	case *Builder: | ||||
| 		bd := condIn.vals[0].(*Builder) | ||||
| 		if _, err := fmt.Fprintf(w, "%s IN (", condIn.col); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		if err := bd.WriteTo(w); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		if _, err := fmt.Fprintf(w, ")"); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	default: | ||||
| 		if len(condIn.vals) <= 0 { | ||||
| 			return ErrNoInConditions | ||||
| 		} | ||||
| 		questionMark := strings.Repeat("?,", len(condIn.vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		w.Append(condIn.vals...) | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (condIn condIn) And(conds ...Cond) Cond { | ||||
| 	return And(condIn, And(conds...)) | ||||
| } | ||||
|  | ||||
| func (condIn condIn) Or(conds ...Cond) Cond { | ||||
| 	return Or(condIn, Or(conds...)) | ||||
| } | ||||
|  | ||||
| func (condIn condIn) IsValid() bool { | ||||
| 	return len(condIn.col) > 0 && len(condIn.vals) > 0 | ||||
| } | ||||
							
								
								
									
										27
									
								
								vendor/github.com/go-xorm/builder/cond_like.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								vendor/github.com/go-xorm/builder/cond_like.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| package builder | ||||
|  | ||||
| import "fmt" | ||||
|  | ||||
| type Like [2]string | ||||
|  | ||||
| var _ Cond = Like{"", ""} | ||||
|  | ||||
| func (like Like) WriteTo(w Writer) error { | ||||
| 	if _, err := fmt.Fprintf(w, "%s LIKE ?", like[0]); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	w.Append("%" + like[1] + "%") | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (like Like) And(conds ...Cond) Cond { | ||||
| 	return And(like, And(conds...)) | ||||
| } | ||||
|  | ||||
| func (like Like) Or(conds ...Cond) Cond { | ||||
| 	return Or(like, Or(conds...)) | ||||
| } | ||||
|  | ||||
| func (like Like) IsValid() bool { | ||||
| 	return len(like[0]) > 0 && len(like[1]) > 0 | ||||
| } | ||||
							
								
								
									
										69
									
								
								vendor/github.com/go-xorm/builder/cond_neq.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								vendor/github.com/go-xorm/builder/cond_neq.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,69 @@ | ||||
| package builder | ||||
|  | ||||
| import "fmt" | ||||
|  | ||||
| type Neq map[string]interface{} | ||||
|  | ||||
| var _ Cond = Neq{} | ||||
|  | ||||
| func (neq Neq) WriteTo(w Writer) error { | ||||
| 	var args = make([]interface{}, 0, len(neq)) | ||||
| 	var i = 0 | ||||
| 	for k, v := range neq { | ||||
| 		switch v.(type) { | ||||
| 		case []int, []int64, []string, []int32, []int16, []int8: | ||||
| 			if err := NotIn(k, v).WriteTo(w); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 		case expr: | ||||
| 			if _, err := fmt.Fprintf(w, "%s<>(", k); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
|  | ||||
| 			if err := v.(expr).WriteTo(w); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
|  | ||||
| 			if _, err := fmt.Fprintf(w, ")"); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 		case *Builder: | ||||
| 			if _, err := fmt.Fprintf(w, "%s<>(", k); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
|  | ||||
| 			if err := v.(*Builder).WriteTo(w); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
|  | ||||
| 			if _, err := fmt.Fprintf(w, ")"); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 		default: | ||||
| 			if _, err := fmt.Fprintf(w, "%s<>?", k); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 			args = append(args, v) | ||||
| 		} | ||||
| 		if i != len(neq)-1 { | ||||
| 			if _, err := fmt.Fprint(w, " AND "); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 		} | ||||
| 		i = i + 1 | ||||
| 	} | ||||
| 	w.Append(args...) | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (neq Neq) And(conds ...Cond) Cond { | ||||
| 	return And(neq, And(conds...)) | ||||
| } | ||||
|  | ||||
| func (neq Neq) Or(conds ...Cond) Cond { | ||||
| 	return Or(neq, Or(conds...)) | ||||
| } | ||||
|  | ||||
| func (neq Neq) IsValid() bool { | ||||
| 	return len(neq) > 0 | ||||
| } | ||||
							
								
								
									
										44
									
								
								vendor/github.com/go-xorm/builder/cond_not.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								vendor/github.com/go-xorm/builder/cond_not.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,44 @@ | ||||
| package builder | ||||
|  | ||||
| import "fmt" | ||||
|  | ||||
| type Not [1]Cond | ||||
|  | ||||
| var _ Cond = Not{} | ||||
|  | ||||
| func (not Not) WriteTo(w Writer) error { | ||||
| 	if _, err := fmt.Fprint(w, "NOT "); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	switch not[0].(type) { | ||||
| 	case condAnd, condOr: | ||||
| 		if _, err := fmt.Fprint(w, "("); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if err := not[0].WriteTo(w); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	switch not[0].(type) { | ||||
| 	case condAnd, condOr: | ||||
| 		if _, err := fmt.Fprint(w, ")"); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (not Not) And(conds ...Cond) Cond { | ||||
| 	return And(not, And(conds...)) | ||||
| } | ||||
|  | ||||
| func (not Not) Or(conds ...Cond) Cond { | ||||
| 	return Or(not, Or(conds...)) | ||||
| } | ||||
|  | ||||
| func (not Not) IsValid() bool { | ||||
| 	return not[0] != nil && not[0].IsValid() | ||||
| } | ||||
							
								
								
									
										206
									
								
								vendor/github.com/go-xorm/builder/cond_notin.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										206
									
								
								vendor/github.com/go-xorm/builder/cond_notin.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,206 @@ | ||||
| package builder | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"strings" | ||||
| ) | ||||
|  | ||||
| type condNotIn condIn | ||||
|  | ||||
| var _ Cond = condNotIn{} | ||||
|  | ||||
| func NotIn(col string, values ...interface{}) Cond { | ||||
| 	return condNotIn{col, values} | ||||
| } | ||||
|  | ||||
| func (condNotIn condNotIn) WriteTo(w Writer) error { | ||||
| 	if len(condNotIn.vals) <= 0 { | ||||
| 		return ErrNoNotInConditions | ||||
| 	} | ||||
|  | ||||
| 	switch condNotIn.vals[0].(type) { | ||||
| 	case []int8: | ||||
| 		vals := condNotIn.vals[0].([]int8) | ||||
| 		if len(vals) <= 0 { | ||||
| 			return ErrNoNotInConditions | ||||
| 		} | ||||
| 		questionMark := strings.Repeat("?,", len(vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		for _, val := range vals { | ||||
| 			w.Append(val) | ||||
| 		} | ||||
| 	case []int16: | ||||
| 		vals := condNotIn.vals[0].([]int16) | ||||
| 		if len(vals) <= 0 { | ||||
| 			return ErrNoNotInConditions | ||||
| 		} | ||||
| 		questionMark := strings.Repeat("?,", len(vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		for _, val := range vals { | ||||
| 			w.Append(val) | ||||
| 		} | ||||
| 	case []int: | ||||
| 		vals := condNotIn.vals[0].([]int) | ||||
| 		if len(vals) <= 0 { | ||||
| 			return ErrNoNotInConditions | ||||
| 		} | ||||
| 		questionMark := strings.Repeat("?,", len(vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		for _, val := range vals { | ||||
| 			w.Append(val) | ||||
| 		} | ||||
| 	case []int32: | ||||
| 		vals := condNotIn.vals[0].([]int32) | ||||
| 		if len(vals) <= 0 { | ||||
| 			return ErrNoNotInConditions | ||||
| 		} | ||||
| 		questionMark := strings.Repeat("?,", len(vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		for _, val := range vals { | ||||
| 			w.Append(val) | ||||
| 		} | ||||
| 	case []int64: | ||||
| 		vals := condNotIn.vals[0].([]int64) | ||||
| 		if len(vals) <= 0 { | ||||
| 			return ErrNoNotInConditions | ||||
| 		} | ||||
| 		questionMark := strings.Repeat("?,", len(vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		for _, val := range vals { | ||||
| 			w.Append(val) | ||||
| 		} | ||||
| 	case []uint8: | ||||
| 		vals := condNotIn.vals[0].([]uint8) | ||||
| 		if len(vals) <= 0 { | ||||
| 			return ErrNoNotInConditions | ||||
| 		} | ||||
| 		questionMark := strings.Repeat("?,", len(vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		for _, val := range vals { | ||||
| 			w.Append(val) | ||||
| 		} | ||||
| 	case []uint16: | ||||
| 		vals := condNotIn.vals[0].([]uint16) | ||||
| 		if len(vals) <= 0 { | ||||
| 			return ErrNoNotInConditions | ||||
| 		} | ||||
| 		questionMark := strings.Repeat("?,", len(vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		for _, val := range vals { | ||||
| 			w.Append(val) | ||||
| 		} | ||||
| 	case []uint: | ||||
| 		vals := condNotIn.vals[0].([]uint) | ||||
| 		if len(vals) <= 0 { | ||||
| 			return ErrNoNotInConditions | ||||
| 		} | ||||
| 		questionMark := strings.Repeat("?,", len(vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		for _, val := range vals { | ||||
| 			w.Append(val) | ||||
| 		} | ||||
| 	case []uint32: | ||||
| 		vals := condNotIn.vals[0].([]uint32) | ||||
| 		if len(vals) <= 0 { | ||||
| 			return ErrNoNotInConditions | ||||
| 		} | ||||
| 		questionMark := strings.Repeat("?,", len(vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		for _, val := range vals { | ||||
| 			w.Append(val) | ||||
| 		} | ||||
| 	case []uint64: | ||||
| 		vals := condNotIn.vals[0].([]uint64) | ||||
| 		if len(vals) <= 0 { | ||||
| 			return ErrNoNotInConditions | ||||
| 		} | ||||
| 		questionMark := strings.Repeat("?,", len(vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		for _, val := range vals { | ||||
| 			w.Append(val) | ||||
| 		} | ||||
| 	case []string: | ||||
| 		vals := condNotIn.vals[0].([]string) | ||||
| 		if len(vals) <= 0 { | ||||
| 			return ErrNoNotInConditions | ||||
| 		} | ||||
| 		questionMark := strings.Repeat("?,", len(vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		for _, val := range vals { | ||||
| 			w.Append(val) | ||||
| 		} | ||||
| 	case []interface{}: | ||||
| 		vals := condNotIn.vals[0].([]interface{}) | ||||
| 		if len(vals) <= 0 { | ||||
| 			return ErrNoNotInConditions | ||||
| 		} | ||||
| 		questionMark := strings.Repeat("?,", len(vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		w.Append(vals...) | ||||
| 	case expr: | ||||
| 		val := condNotIn.vals[0].(expr) | ||||
| 		if _, err := fmt.Fprintf(w, "%s NOT IN (", condNotIn.col); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		if err := val.WriteTo(w); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		if _, err := fmt.Fprintf(w, ")"); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	case *Builder: | ||||
| 		val := condNotIn.vals[0].(*Builder) | ||||
| 		if _, err := fmt.Fprintf(w, "%s NOT IN (", condNotIn.col); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		if err := val.WriteTo(w); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		if _, err := fmt.Fprintf(w, ")"); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	default: | ||||
| 		questionMark := strings.Repeat("?,", len(condNotIn.vals)) | ||||
| 		if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		w.Append(condNotIn.vals...) | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (condNotIn condNotIn) And(conds ...Cond) Cond { | ||||
| 	return And(condNotIn, And(conds...)) | ||||
| } | ||||
|  | ||||
| func (condNotIn condNotIn) Or(conds ...Cond) Cond { | ||||
| 	return Or(condNotIn, Or(conds...)) | ||||
| } | ||||
|  | ||||
| func (condNotIn condNotIn) IsValid() bool { | ||||
| 	return len(condNotIn.col) > 0 && len(condNotIn.vals) > 0 | ||||
| } | ||||
							
								
								
									
										47
									
								
								vendor/github.com/go-xorm/builder/cond_null.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								vendor/github.com/go-xorm/builder/cond_null.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,47 @@ | ||||
| package builder | ||||
|  | ||||
| import "fmt" | ||||
|  | ||||
| // IsNull | ||||
| type IsNull [1]string | ||||
|  | ||||
| var _ Cond = IsNull{""} | ||||
|  | ||||
| func (isNull IsNull) WriteTo(w Writer) error { | ||||
| 	_, err := fmt.Fprintf(w, "%s IS NULL", isNull[0]) | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| func (isNull IsNull) And(conds ...Cond) Cond { | ||||
| 	return And(isNull, And(conds...)) | ||||
| } | ||||
|  | ||||
| func (isNull IsNull) Or(conds ...Cond) Cond { | ||||
| 	return Or(isNull, Or(conds...)) | ||||
| } | ||||
|  | ||||
| func (isNull IsNull) IsValid() bool { | ||||
| 	return len(isNull[0]) > 0 | ||||
| } | ||||
|  | ||||
| // NotNull | ||||
| type NotNull [1]string | ||||
|  | ||||
| var _ Cond = NotNull{""} | ||||
|  | ||||
| func (notNull NotNull) WriteTo(w Writer) error { | ||||
| 	_, err := fmt.Fprintf(w, "%s IS NOT NULL", notNull[0]) | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| func (notNull NotNull) And(conds ...Cond) Cond { | ||||
| 	return And(notNull, And(conds...)) | ||||
| } | ||||
|  | ||||
| func (notNull NotNull) Or(conds ...Cond) Cond { | ||||
| 	return Or(notNull, Or(conds...)) | ||||
| } | ||||
|  | ||||
| func (notNull NotNull) IsValid() bool { | ||||
| 	return len(notNull[0]) > 0 | ||||
| } | ||||
							
								
								
									
										61
									
								
								vendor/github.com/go-xorm/builder/cond_or.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								vendor/github.com/go-xorm/builder/cond_or.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,61 @@ | ||||
| package builder | ||||
|  | ||||
| import "fmt" | ||||
|  | ||||
| type condOr []Cond | ||||
|  | ||||
| var _ Cond = condOr{} | ||||
|  | ||||
| func Or(conds ...Cond) Cond { | ||||
| 	var result = make(condOr, 0, len(conds)) | ||||
| 	for _, cond := range conds { | ||||
| 		if cond == nil || !cond.IsValid() { | ||||
| 			continue | ||||
| 		} | ||||
| 		result = append(result, cond) | ||||
| 	} | ||||
| 	return result | ||||
| } | ||||
|  | ||||
| func (or condOr) WriteTo(w Writer) error { | ||||
| 	for i, cond := range or { | ||||
| 		var needQuote bool | ||||
| 		switch cond.(type) { | ||||
| 		case condAnd: | ||||
| 			needQuote = true | ||||
| 		case Eq: | ||||
| 			needQuote = (len(cond.(Eq)) > 1) | ||||
| 		} | ||||
|  | ||||
| 		if needQuote { | ||||
| 			fmt.Fprint(w, "(") | ||||
| 		} | ||||
|  | ||||
| 		err := cond.WriteTo(w) | ||||
| 		if err != nil { | ||||
| 			return err | ||||
| 		} | ||||
|  | ||||
| 		if needQuote { | ||||
| 			fmt.Fprint(w, ")") | ||||
| 		} | ||||
|  | ||||
| 		if i != len(or)-1 { | ||||
| 			fmt.Fprint(w, " OR ") | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (o condOr) And(conds ...Cond) Cond { | ||||
| 	return And(o, And(conds...)) | ||||
| } | ||||
|  | ||||
| func (o condOr) Or(conds ...Cond) Cond { | ||||
| 	return Or(o, Or(conds...)) | ||||
| } | ||||
|  | ||||
| func (o condOr) IsValid() bool { | ||||
| 	return len(o) > 0 | ||||
| } | ||||
							
								
								
									
										120
									
								
								vendor/github.com/go-xorm/builder/doc.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										120
									
								
								vendor/github.com/go-xorm/builder/doc.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,120 @@ | ||||
| // Copyright 2016 The XORM Authors. All rights reserved. | ||||
| // Use of this source code is governed by a BSD | ||||
| // license that can be found in the LICENSE file. | ||||
|  | ||||
| /* | ||||
|  | ||||
| Package builder is a simple and powerful sql builder for Go. | ||||
|  | ||||
| Make sure you have installed Go 1.1+ and then: | ||||
|  | ||||
|     go get github.com/go-xorm/builder | ||||
|  | ||||
| WARNNING: Currently, only query conditions are supported. Below is the supported conditions. | ||||
|  | ||||
| 1. Eq is a redefine of a map, you can give one or more conditions to Eq | ||||
|  | ||||
|     import . "github.com/go-xorm/builder" | ||||
|  | ||||
|     sql, args, _ := ToSQL(Eq{"a":1}) | ||||
|     // a=? [1] | ||||
|     sql, args, _ := ToSQL(Eq{"b":"c"}.And(Eq{"c": 0})) | ||||
|     // b=? AND c=? ["c", 0] | ||||
|     sql, args, _ := ToSQL(Eq{"b":"c", "c":0}) | ||||
|     // b=? AND c=? ["c", 0] | ||||
|     sql, args, _ := ToSQL(Eq{"b":"c"}.Or(Eq{"b":"d"})) | ||||
|     // b=? OR b=? ["c", "d"] | ||||
|     sql, args, _ := ToSQL(Eq{"b": []string{"c", "d"}}) | ||||
|     // b IN (?,?) ["c", "d"] | ||||
|     sql, args, _ := ToSQL(Eq{"b": 1, "c":[]int{2, 3}}) | ||||
|     // b=? AND c IN (?,?) [1, 2, 3] | ||||
|  | ||||
| 2. Neq is the same to Eq | ||||
|  | ||||
|     import . "github.com/go-xorm/builder" | ||||
|  | ||||
|     sql, args, _ := ToSQL(Neq{"a":1}) | ||||
|     // a<>? [1] | ||||
|     sql, args, _ := ToSQL(Neq{"b":"c"}.And(Neq{"c": 0})) | ||||
|     // b<>? AND c<>? ["c", 0] | ||||
|     sql, args, _ := ToSQL(Neq{"b":"c", "c":0}) | ||||
|     // b<>? AND c<>? ["c", 0] | ||||
|     sql, args, _ := ToSQL(Neq{"b":"c"}.Or(Neq{"b":"d"})) | ||||
|     // b<>? OR b<>? ["c", "d"] | ||||
|     sql, args, _ := ToSQL(Neq{"b": []string{"c", "d"}}) | ||||
|     // b NOT IN (?,?) ["c", "d"] | ||||
|     sql, args, _ := ToSQL(Neq{"b": 1, "c":[]int{2, 3}}) | ||||
|     // b<>? AND c NOT IN (?,?) [1, 2, 3] | ||||
|  | ||||
| 3. Gt, Gte, Lt, Lte | ||||
|  | ||||
|     import . "github.com/go-xorm/builder" | ||||
|  | ||||
|     sql, args, _ := ToSQL(Gt{"a", 1}.And(Gte{"b", 2})) | ||||
|     // a>? AND b>=? [1, 2] | ||||
|     sql, args, _ := ToSQL(Lt{"a", 1}.Or(Lte{"b", 2})) | ||||
|     // a<? OR b<=? [1, 2] | ||||
|  | ||||
| 4. Like | ||||
|  | ||||
|     import . "github.com/go-xorm/builder" | ||||
|  | ||||
|     sql, args, _ := ToSQL(Like{"a", "c"}) | ||||
|     // a LIKE ? [%c%] | ||||
|  | ||||
| 5. Expr you can customerize your sql with Expr | ||||
|  | ||||
|     import . "github.com/go-xorm/builder" | ||||
|  | ||||
|     sql, args, _ := ToSQL(Expr("a = ? ", 1)) | ||||
|     // a = ? [1] | ||||
|     sql, args, _ := ToSQL(Eq{"a": Expr("select id from table where c = ?", 1)}) | ||||
|     // a=(select id from table where c = ?) [1] | ||||
|  | ||||
| 6. In and NotIn | ||||
|  | ||||
|     import . "github.com/go-xorm/builder" | ||||
|  | ||||
|     sql, args, _ := ToSQL(In("a", 1, 2, 3)) | ||||
|     // a IN (?,?,?) [1,2,3] | ||||
|     sql, args, _ := ToSQL(In("a", []int{1, 2, 3})) | ||||
|     // a IN (?,?,?) [1,2,3] | ||||
|     sql, args, _ := ToSQL(In("a", Expr("select id from b where c = ?", 1)))) | ||||
|     // a IN (select id from b where c = ?) [1] | ||||
|  | ||||
| 7. IsNull and NotNull | ||||
|  | ||||
|     import . "github.com/go-xorm/builder" | ||||
|  | ||||
|     sql, args, _ := ToSQL(IsNull{"a"}) | ||||
|     // a IS NULL [] | ||||
|     sql, args, _ := ToSQL(NotNull{"b"}) | ||||
|      // b IS NOT NULL [] | ||||
|  | ||||
| 8. And(conds ...Cond), And can connect one or more condtions via AND | ||||
|  | ||||
|     import . "github.com/go-xorm/builder" | ||||
|  | ||||
|     sql, args, _ := ToSQL(And(Eq{"a":1}, Like{"b", "c"}, Neq{"d", 2})) | ||||
|     // a=? AND b LIKE ? AND d<>? [1, %c%, 2] | ||||
|  | ||||
| 9. Or(conds ...Cond), Or can connect one or more conditions via Or | ||||
|  | ||||
|     import . "github.com/go-xorm/builder" | ||||
|  | ||||
|     sql, args, _ := ToSQL(Or(Eq{"a":1}, Like{"b", "c"}, Neq{"d", 2})) | ||||
|     // a=? OR b LIKE ? OR d<>? [1, %c%, 2] | ||||
|     sql, args, _ := ToSQL(Or(Eq{"a":1}, And(Like{"b", "c"}, Neq{"d", 2}))) | ||||
|     // a=? OR (b LIKE ? AND d<>?) [1, %c%, 2] | ||||
|  | ||||
| 10. Between | ||||
|  | ||||
|     import . "github.com/go-xorm/builder" | ||||
|  | ||||
|     sql, args, _ := ToSQL(Between("a", 1, 2)) | ||||
|     // a BETWEEN 1 AND 2 | ||||
|  | ||||
| 11. define yourself conditions | ||||
| Since Cond is a interface, you can define yourself conditions and compare with them | ||||
| */ | ||||
| package builder | ||||
							
								
								
									
										9
									
								
								vendor/github.com/go-xorm/builder/error.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								vendor/github.com/go-xorm/builder/error.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| package builder | ||||
|  | ||||
| import "errors" | ||||
|  | ||||
| var ( | ||||
| 	ErrNotSupportType    = errors.New("not supported SQL type") | ||||
| 	ErrNoNotInConditions = errors.New("No NOT IN conditions") | ||||
| 	ErrNoInConditions    = errors.New("No IN conditions") | ||||
| ) | ||||
		Reference in New Issue
	
	Block a user