mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-27 09:11:53 -05:00
980dd0bf51
* update xorm and dependencies vendor for feature to dump to other database * fix golint
78 lines
1.6 KiB
Go
78 lines
1.6 KiB
Go
// Copyright 2016 The Xorm Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package builder
|
|
|
|
import "fmt"
|
|
|
|
// Neq defines not equal conditions
|
|
type Neq map[string]interface{}
|
|
|
|
var _ Cond = Neq{}
|
|
|
|
// WriteTo writes SQL to Writer
|
|
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
|
|
}
|
|
|
|
// And implements And with other conditions
|
|
func (neq Neq) And(conds ...Cond) Cond {
|
|
return And(neq, And(conds...))
|
|
}
|
|
|
|
// Or implements Or with other conditions
|
|
func (neq Neq) Or(conds ...Cond) Cond {
|
|
return Or(neq, Or(conds...))
|
|
}
|
|
|
|
// IsValid tests if this condition is valid
|
|
func (neq Neq) IsValid() bool {
|
|
return len(neq) > 0
|
|
}
|