作者 yangfu

query exists

... ... @@ -100,3 +100,21 @@ func(s *SqlExcutor)Querys(v interface{})(total int,err error){
}
return
}
//查询是否存在
func(s *SqlExcutor)QueryExists()(exists bool,err error){
var total int
o :=orm.NewOrm()
_,sqlCount,err :=s.Strings()
sqlCount=strings.Replace(sqlCount,"select count(0) ","select 1 ",1)
if !s.islimit{
sqlCount = sqlCount +" limit 1"
}
if err=o.Raw(sqlCount).QueryRow(&total);err!=nil{
return
}
exists = false
if total==1{
exists = true
}
return
}
... ...