Add And and Or method for query condition
This commit is contained in:
parent
a1062be8d0
commit
2a6991886c
|
@ -21,3 +21,4 @@ _cgo_export.*
|
|||
_testmain.go
|
||||
|
||||
*.exe
|
||||
vendor
|
||||
|
|
|
@ -452,6 +452,13 @@ func where(engine *Engine, t *testing.T) {
|
|||
panic(err)
|
||||
}
|
||||
fmt.Println(users)
|
||||
|
||||
err = engine.Where("(id) > ?", 2).And("(id) < ?", 10).Find(&users)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(users)
|
||||
}
|
||||
|
||||
func in(engine *Engine, t *testing.T) {
|
||||
|
|
20
install
20
install
|
@ -1,20 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
if [ ! -f install ]; then
|
||||
echo 'install must be run within its container folder' 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CURDIR=`pwd`
|
||||
NEWPATH="$GOPATH/src/github.com/lunny/${PWD##*/}"
|
||||
if [ ! -d "$NEWPATH" ]; then
|
||||
ln -s $CURDIR $NEWPATH
|
||||
fi
|
||||
|
||||
gofmt -w $CURDIR
|
||||
|
||||
cd $NEWPATH
|
||||
go install ${PWD##*/}
|
||||
cd $CURDIR
|
||||
|
||||
echo 'finished'
|
12
session.go
12
session.go
|
@ -58,6 +58,18 @@ func (session *Session) Where(querystring string, args ...interface{}) *Session
|
|||
return session
|
||||
}
|
||||
|
||||
// Method Where provides custom query condition.
|
||||
func (session *Session) And(querystring string, args ...interface{}) *Session {
|
||||
session.Statement.And(querystring, args...)
|
||||
return session
|
||||
}
|
||||
|
||||
// Method Where provides custom query condition.
|
||||
func (session *Session) Or(querystring string, args ...interface{}) *Session {
|
||||
session.Statement.Or(querystring, args...)
|
||||
return session
|
||||
}
|
||||
|
||||
// Method Id provides converting id as a query condition
|
||||
func (session *Session) Id(id int64) *Session {
|
||||
session.Statement.Id(id)
|
||||
|
|
18
statement.go
18
statement.go
|
@ -69,6 +69,24 @@ func (statement *Statement) Where(querystring string, args ...interface{}) {
|
|||
statement.Params = args
|
||||
}
|
||||
|
||||
func (statement *Statement) And(querystring string, args ...interface{}) {
|
||||
if statement.WhereStr != "" {
|
||||
statement.WhereStr = fmt.Sprintf("(%v) AND (%v)", statement.WhereStr, querystring)
|
||||
} else {
|
||||
statement.WhereStr = querystring
|
||||
}
|
||||
statement.Params = append(statement.Params, args...)
|
||||
}
|
||||
|
||||
func (statement *Statement) Or(querystring string, args ...interface{}) {
|
||||
if statement.WhereStr != "" {
|
||||
statement.WhereStr = fmt.Sprintf("(%v) OR (%v)", statement.WhereStr, querystring)
|
||||
} else {
|
||||
statement.WhereStr = querystring
|
||||
}
|
||||
statement.Params = append(statement.Params, args...)
|
||||
}
|
||||
|
||||
func (statement *Statement) Table(tableNameOrBean interface{}) {
|
||||
t := rType(tableNameOrBean)
|
||||
if t.Kind() == reflect.String {
|
||||
|
|
Loading…
Reference in New Issue