parent
8700152b6c
commit
fad61020e8
|
@ -320,6 +320,12 @@ func (engine *Engine) NoAutoTime() *Session {
|
|||
return session.NoAutoTime()
|
||||
}
|
||||
|
||||
func (engine *Engine) NoAutoCondition(no ...bool) *Session {
|
||||
session := engine.NewSession()
|
||||
session.IsAutoClose = true
|
||||
return session.NoAutoCondition(no...)
|
||||
}
|
||||
|
||||
// Retrieve all tables, columns, indexes' informations from database.
|
||||
func (engine *Engine) DBMetas() ([]*core.Table, error) {
|
||||
tables, err := engine.dialect.GetTables()
|
||||
|
|
17
session.go
17
session.go
|
@ -258,6 +258,11 @@ func (session *Session) NoAutoTime() *Session {
|
|||
return session
|
||||
}
|
||||
|
||||
func (session *Session) NoAutoCondition(no ...bool) *Session {
|
||||
session.Statement.NoAutoCondition(no...)
|
||||
return session
|
||||
}
|
||||
|
||||
// Method Limit provide limit and offset query condition
|
||||
func (session *Session) Limit(limit int, start ...int) *Session {
|
||||
session.Statement.Limit(limit, start...)
|
||||
|
@ -1219,7 +1224,7 @@ func (session *Session) Find(rowsSlicePtr interface{}, condiBean ...interface{})
|
|||
}
|
||||
|
||||
var addedTableName = (len(session.Statement.JoinStr) > 0)
|
||||
if len(condiBean) > 0 {
|
||||
if !session.Statement.noAutoCondition && len(condiBean) > 0 {
|
||||
colNames, args := buildConditions(session.Engine, table, condiBean[0], true, true,
|
||||
false, true, session.Statement.allUseBool, session.Statement.useAllCols,
|
||||
session.Statement.unscoped, session.Statement.mustColumnMap,
|
||||
|
@ -3635,7 +3640,7 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
|||
var condiColNames []string
|
||||
var condiArgs []interface{}
|
||||
|
||||
if len(condiBean) > 0 {
|
||||
if !session.Statement.noAutoCondition && len(condiBean) > 0 {
|
||||
condiColNames, condiArgs = buildConditions(session.Engine, session.Statement.RefTable, condiBean[0], true, true,
|
||||
false, true, session.Statement.allUseBool, session.Statement.useAllCols,
|
||||
session.Statement.unscoped, session.Statement.mustColumnMap, session.Statement.TableName(), false)
|
||||
|
@ -3857,11 +3862,15 @@ func (session *Session) Delete(bean interface{}) (int64, error) {
|
|||
|
||||
table := session.Engine.TableInfo(bean)
|
||||
session.Statement.RefTable = table
|
||||
colNames, args := buildConditions(session.Engine, table, bean, true, true,
|
||||
var colNames []string
|
||||
var args []interface{}
|
||||
|
||||
if !session.Statement.noAutoCondition {
|
||||
colNames, args = buildConditions(session.Engine, table, bean, true, true,
|
||||
false, true, session.Statement.allUseBool, session.Statement.useAllCols,
|
||||
session.Statement.unscoped, session.Statement.mustColumnMap,
|
||||
session.Statement.TableName(), false)
|
||||
|
||||
}
|
||||
var condition = ""
|
||||
var andStr = session.Engine.dialect.AndStr()
|
||||
|
||||
|
|
15
statement.go
15
statement.go
|
@ -66,6 +66,7 @@ type Statement struct {
|
|||
BeanArgs []interface{}
|
||||
UseCache bool
|
||||
UseAutoTime bool
|
||||
noAutoCondition bool
|
||||
IsDistinct bool
|
||||
IsForUpdate bool
|
||||
TableAlias string
|
||||
|
@ -103,6 +104,7 @@ func (statement *Statement) Init() {
|
|||
statement.BeanArgs = make([]interface{}, 0)
|
||||
statement.UseCache = true
|
||||
statement.UseAutoTime = true
|
||||
statement.noAutoCondition = false
|
||||
statement.IsDistinct = false
|
||||
statement.IsForUpdate = false
|
||||
statement.TableAlias = ""
|
||||
|
@ -119,6 +121,15 @@ func (statement *Statement) Init() {
|
|||
statement.exprColumns = make(map[string]exprParam)
|
||||
}
|
||||
|
||||
// NoAutoCondition
|
||||
func (statement *Statement) NoAutoCondition(no ...bool) *Statement {
|
||||
statement.noAutoCondition = true
|
||||
if len(no) > 0 {
|
||||
statement.noAutoCondition = no[0]
|
||||
}
|
||||
return statement
|
||||
}
|
||||
|
||||
// add the raw sql statement
|
||||
func (statement *Statement) Sql(querystring string, args ...interface{}) *Statement {
|
||||
statement.RawSQL = querystring
|
||||
|
@ -1111,12 +1122,14 @@ func (statement *Statement) genGetSql(bean interface{}) (string, []interface{})
|
|||
|
||||
var addedTableName = (len(statement.JoinStr) > 0)
|
||||
|
||||
if !statement.noAutoCondition {
|
||||
colNames, args := buildConditions(statement.Engine, table, bean, true, true,
|
||||
false, true, statement.allUseBool, statement.useAllCols,
|
||||
statement.unscoped, statement.mustColumnMap, statement.TableName(), addedTableName)
|
||||
|
||||
statement.ConditionStr = strings.Join(colNames, " "+statement.Engine.dialect.AndStr()+" ")
|
||||
statement.BeanArgs = args
|
||||
}
|
||||
|
||||
var columnStr string = statement.ColumnStr
|
||||
if len(statement.selectStr) > 0 {
|
||||
|
@ -1172,12 +1185,14 @@ func (statement *Statement) genCountSql(bean interface{}) (string, []interface{}
|
|||
|
||||
var addedTableName = (len(statement.JoinStr) > 0)
|
||||
|
||||
if !statement.noAutoCondition {
|
||||
colNames, args := buildConditions(statement.Engine, table, bean, true, true, false,
|
||||
true, statement.allUseBool, statement.useAllCols,
|
||||
statement.unscoped, statement.mustColumnMap, statement.TableName(), addedTableName)
|
||||
|
||||
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