diff --git a/.gitignore b/.gitignore index d44e3d8f..4d7cf444 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ _cgo_export.* _testmain.go *.exe +vendor diff --git a/.gopmfile b/.gopmfile new file mode 100644 index 00000000..3590b536 --- /dev/null +++ b/.gopmfile @@ -0,0 +1,2 @@ +[target] +path = github.com/lunny/xorm \ No newline at end of file diff --git a/base_test.go b/base_test.go index 3436a584..66144b90 100644 --- a/base_test.go +++ b/base_test.go @@ -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) { diff --git a/install b/install deleted file mode 100755 index 53326e0b..00000000 --- a/install +++ /dev/null @@ -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' diff --git a/session.go b/session.go index 63350459..4f0146af 100644 --- a/session.go +++ b/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) diff --git a/statement.go b/statement.go index a06d4ee9..acadf25b 100644 --- a/statement.go +++ b/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 {