lj-wsdj 2024-08-10 11:39:59 +08:00
parent 91013ab523
commit 51af81d925
2 changed files with 10 additions and 10 deletions

View File

@ -24,8 +24,8 @@ func (s *SqlBuilder[T]) Conditions(cond string, args ...interface{}) {
} else { } else {
cond, args = dealInCondition(cond, args) cond, args = dealInCondition(cond, args)
} }
s.Opts.conditions = append(s.Opts.conditions, cond) s.Opts.Conditions = append(s.Opts.Conditions, cond)
s.Opts.args = append(s.Opts.args, args...) s.Opts.Args = append(s.Opts.Args, args...)
s.buildCondition(util.ConditionPlaceholder, cond) s.buildCondition(util.ConditionPlaceholder, cond)
} }
@ -38,8 +38,8 @@ func (s *SqlBuilder[T]) InsertConditions(symbol string, cond string, args ...int
} else { } else {
cond, args = dealInCondition(cond, args) cond, args = dealInCondition(cond, args)
} }
s.Opts.conditions = append(s.Opts.conditions, cond) s.Opts.Conditions = append(s.Opts.Conditions, cond)
s.Opts.args = append(s.Opts.args, args...) s.Opts.Args = append(s.Opts.Args, args...)
s.buildCondition(symbol, cond) s.buildCondition(symbol, cond)
} }

View File

@ -25,8 +25,8 @@ type SqlBuilder[T tydb.QOneRowRst | tytaos.QOneRowRst | tyoracle.QOneRowRst | in
type Options struct { type Options struct {
util.Page util.Page
selects []string selects []string
conditions []string Conditions []string
args []interface{} // condition的参数 Args []interface{} // condition的参数
groups []string groups []string
orders []string orders []string
partitions []string // tdengine专用 partitions []string // tdengine专用
@ -55,12 +55,12 @@ func (s *SqlBuilder[T]) SetDriver(driver string) {
func (s *SqlBuilder[T]) FindBySql(data interface{}) error { func (s *SqlBuilder[T]) FindBySql(data interface{}) error {
sqls := s.buildSql() sqls := s.buildSql()
return s.Connector.QueryEx(sqls, data, s.Opts.args...) return s.Connector.QueryEx(sqls, data, s.Opts.Args...)
} }
func (s *SqlBuilder[T]) FindOneBySql(data interface{}) error { func (s *SqlBuilder[T]) FindOneBySql(data interface{}) error {
sqls := s.buildSql() sqls := s.buildSql()
err, _ := s.Connector.QueryRow(sqls, data, s.Opts.args...) err, _ := s.Connector.QueryRow(sqls, data, s.Opts.Args...)
return err return err
} }
@ -71,11 +71,11 @@ func (s *SqlBuilder[T]) PaginateBySql(data interface{}, page util.Page) error {
sqls := s.buildSql() sqls := s.buildSql()
count_sql := s.buildCountSql(sqls) count_sql := s.buildCountSql(sqls)
paginage_sql := s.buildPaginateSql(sqls) paginage_sql := s.buildPaginateSql(sqls)
err, _ = s.Connector.QueryRow(count_sql, &total, s.Opts.args...) err, _ = s.Connector.QueryRow(count_sql, &total, s.Opts.Args...)
if err != nil { if err != nil {
return err return err
} }
s.Opts.Page.SetTotal(total) s.Opts.Page.SetTotal(total)
err = s.Connector.QueryEx(paginage_sql, data, s.Opts.args...) err = s.Connector.QueryEx(paginage_sql, data, s.Opts.Args...)
return err return err
} }