1)add "WhereOnly" function provides custom query condition without bean's non-empty fields for "Get" and "Count"
This commit is contained in:
parent
1992491553
commit
51ccecdbc4
|
@ -466,6 +466,13 @@ func (engine *Engine) Where(querystring string, args ...interface{}) *Session {
|
|||
return session.Where(querystring, args...)
|
||||
}
|
||||
|
||||
// Where method provide a condition query without bean's non-empty fields.
|
||||
func (engine *Engine) WhereOnly(querystring string, args ...interface{}) *Session {
|
||||
session := engine.NewSession()
|
||||
session.IsAutoClose = true
|
||||
return session.WhereOnly(querystring, args...)
|
||||
}
|
||||
|
||||
// Id mehtod provoide a condition as (id) = ?
|
||||
func (engine *Engine) Id(id interface{}) *Session {
|
||||
session := engine.NewSession()
|
||||
|
|
|
@ -102,6 +102,12 @@ func (session *Session) Where(querystring string, args ...interface{}) *Session
|
|||
return session
|
||||
}
|
||||
|
||||
// Method Where provides custom query condition without bean's non-empty fields.
|
||||
func (session *Session) WhereOnly(querystring string, args ...interface{}) *Session {
|
||||
session.Statement.WhereOnly(querystring, args...)
|
||||
return session
|
||||
}
|
||||
|
||||
// Method Where provides custom query condition.
|
||||
func (session *Session) And(querystring string, args ...interface{}) *Session {
|
||||
session.Statement.And(querystring, args...)
|
||||
|
|
27
statement.go
27
statement.go
|
@ -73,6 +73,8 @@ type Statement struct {
|
|||
incrColumns map[string]incrParam
|
||||
decrColumns map[string]decrParam
|
||||
exprColumns map[string]exprParam
|
||||
|
||||
IsWhereOnly bool
|
||||
}
|
||||
|
||||
// init
|
||||
|
@ -109,6 +111,8 @@ func (statement *Statement) Init() {
|
|||
statement.incrColumns = make(map[string]incrParam)
|
||||
statement.decrColumns = make(map[string]decrParam)
|
||||
statement.exprColumns = make(map[string]exprParam)
|
||||
|
||||
statement.IsWhereOnly = false
|
||||
}
|
||||
|
||||
// add the raw sql statement
|
||||
|
@ -134,6 +138,17 @@ func (statement *Statement) Where(querystring string, args ...interface{}) *Stat
|
|||
return statement
|
||||
}
|
||||
|
||||
// add where statment without bean's non-empty fields for Get Count
|
||||
func (statement *Statement) WhereOnly(querystring string, args ...interface{}) *Statement {
|
||||
if !strings.Contains(querystring, statement.Engine.dialect.EqStr()) {
|
||||
querystring = strings.Replace(querystring, "=", statement.Engine.dialect.EqStr(), -1)
|
||||
}
|
||||
statement.WhereStr = querystring
|
||||
statement.Params = args
|
||||
statement.IsWhereOnly = true
|
||||
return statement
|
||||
}
|
||||
|
||||
// add Where & and statment
|
||||
func (statement *Statement) And(querystring string, args ...interface{}) *Statement {
|
||||
if statement.WhereStr != "" {
|
||||
|
@ -1142,8 +1157,10 @@ func (statement *Statement) genGetSql(bean interface{}) (string, []interface{})
|
|||
false, true, statement.allUseBool, statement.useAllCols,
|
||||
statement.unscoped, statement.mustColumnMap)
|
||||
|
||||
statement.ConditionStr = strings.Join(colNames, " "+statement.Engine.dialect.AndStr()+" ")
|
||||
statement.BeanArgs = args
|
||||
if !statement.IsWhereOnly {
|
||||
statement.ConditionStr = strings.Join(colNames, " "+statement.Engine.dialect.AndStr()+" ")
|
||||
statement.BeanArgs = args
|
||||
}
|
||||
|
||||
var columnStr string = statement.ColumnStr
|
||||
if len(statement.JoinStr) == 0 {
|
||||
|
@ -1197,8 +1214,10 @@ func (statement *Statement) genCountSql(bean interface{}) (string, []interface{}
|
|||
true, statement.allUseBool, statement.useAllCols,
|
||||
statement.unscoped, statement.mustColumnMap)
|
||||
|
||||
statement.ConditionStr = strings.Join(colNames, " "+statement.Engine.Dialect().AndStr()+" ")
|
||||
statement.BeanArgs = args
|
||||
if !statement.IsWhereOnly {
|
||||
statement.ConditionStr = strings.Join(colNames, " "+statement.Engine.Dialect().AndStr()+" ")
|
||||
statement.BeanArgs = args
|
||||
}
|
||||
|
||||
// count(index fieldname) > count(0) > count(*)
|
||||
var id string = "*"
|
||||
|
|
Loading…
Reference in New Issue