1
// Copyright 2016 The Xorm Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
9
// WriteMap writes conditions' SQL to Writer, op could be =, <>, >, <, <=, >= and etc.
10
func WriteMap(w Writer, data map[string]interface{}, op string) error {
11
var args = make([]interface{}, 0, len(data))
13
for k, v := range data {
16
if _, err := fmt.Fprintf(w, "%s%s(", k, op); err != nil {
20
if err := v.(expr).WriteTo(w); err != nil {
24
if _, err := fmt.Fprintf(w, ")"); err != nil {
28
if _, err := fmt.Fprintf(w, "%s%s(", k, op); err != nil {
32
if err := v.(*Builder).WriteTo(w); err != nil {
36
if _, err := fmt.Fprintf(w, ")"); err != nil {
40
if _, err := fmt.Fprintf(w, "%s%s?", k, op); err != nil {
43
args = append(args, v)
46
if _, err := fmt.Fprint(w, " AND "); err != nil {
56
// Lt defines < condition
57
type Lt map[string]interface{}
61
// WriteTo write SQL to Writer
62
func (lt Lt) WriteTo(w Writer) error {
63
return WriteMap(w, lt, "<")
66
// And implements And with other conditions
67
func (lt Lt) And(conds ...Cond) Cond {
68
return condAnd{lt, And(conds...)}
71
// Or implements Or with other conditions
72
func (lt Lt) Or(conds ...Cond) Cond {
73
return condOr{lt, Or(conds...)}
76
// IsValid tests if this Eq is valid
77
func (lt Lt) IsValid() bool {
81
// Lte defines <= condition
82
type Lte map[string]interface{}
86
// WriteTo write SQL to Writer
87
func (lte Lte) WriteTo(w Writer) error {
88
return WriteMap(w, lte, "<=")
91
// And implements And with other conditions
92
func (lte Lte) And(conds ...Cond) Cond {
93
return And(lte, And(conds...))
96
// Or implements Or with other conditions
97
func (lte Lte) Or(conds ...Cond) Cond {
98
return Or(lte, Or(conds...))
101
// IsValid tests if this Eq is valid
102
func (lte Lte) IsValid() bool {
106
// Gt defines > condition
107
type Gt map[string]interface{}
111
// WriteTo write SQL to Writer
112
func (gt Gt) WriteTo(w Writer) error {
113
return WriteMap(w, gt, ">")
116
// And implements And with other conditions
117
func (gt Gt) And(conds ...Cond) Cond {
118
return And(gt, And(conds...))
121
// Or implements Or with other conditions
122
func (gt Gt) Or(conds ...Cond) Cond {
123
return Or(gt, Or(conds...))
126
// IsValid tests if this Eq is valid
127
func (gt Gt) IsValid() bool {
131
// Gte defines >= condition
132
type Gte map[string]interface{}
136
// WriteTo write SQL to Writer
137
func (gte Gte) WriteTo(w Writer) error {
138
return WriteMap(w, gte, ">=")
141
// And implements And with other conditions
142
func (gte Gte) And(conds ...Cond) Cond {
143
return And(gte, And(conds...))
146
// Or implements Or with other conditions
147
func (gte Gte) Or(conds ...Cond) Cond {
148
return Or(gte, Or(conds...))
151
// IsValid tests if this Eq is valid
152
func (gte Gte) IsValid() bool {