fix
parent
d06f44e671
commit
6439b9e69c
20
db/build.go
20
db/build.go
|
@ -25,34 +25,54 @@ func (s *SqlBuilder[T]) buildCountSql(sqls string) string {
|
|||
|
||||
func (s *SqlBuilder[T]) buildSelect(selects ...string) {
|
||||
for _, v := range selects {
|
||||
if strings.HasPrefix(v, "select") {
|
||||
s.Sql = strings.Replace(s.Sql, util.SelectPlaceholder, fmt.Sprintf("%s", v), 1)
|
||||
} else {
|
||||
s.Sql = strings.Replace(s.Sql, util.SelectPlaceholder, fmt.Sprintf(",%s", v), 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SqlBuilder[T]) buildCondition(conds ...string) {
|
||||
for _, v := range conds {
|
||||
if strings.HasPrefix(v, "where") {
|
||||
s.Sql = strings.Replace(s.Sql, util.ConditionPlaceholder, fmt.Sprintf(" %s", v), 1)
|
||||
} else {
|
||||
s.Sql = strings.Replace(s.Sql, util.ConditionPlaceholder, fmt.Sprintf(" and %s", v), 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SqlBuilder[T]) buildGroup(groups ...string) {
|
||||
for _, v := range groups {
|
||||
if strings.HasPrefix(v, "group by") {
|
||||
s.Sql = strings.Replace(s.Sql, util.GroupPlaceholder, fmt.Sprintf("%s", v), 1)
|
||||
} else {
|
||||
s.Sql = strings.Replace(s.Sql, util.GroupPlaceholder, fmt.Sprintf(",%s", v), 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SqlBuilder[T]) buildOrder(orders ...string) {
|
||||
for _, v := range orders {
|
||||
if strings.HasPrefix(v, "order by") {
|
||||
s.Sql = strings.Replace(s.Sql, util.OrderPlaceholder, fmt.Sprintf("%s", v), 1)
|
||||
} else {
|
||||
s.Sql = strings.Replace(s.Sql, util.OrderPlaceholder, fmt.Sprintf(",%s", v), 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// tdengine专用
|
||||
func (s *SqlBuilder[T]) buildPartition(partitions ...string) {
|
||||
for _, v := range partitions {
|
||||
if strings.HasPrefix(v, "partition by") {
|
||||
s.Sql = strings.Replace(s.Sql, util.PartitionPlaceholder, fmt.Sprintf("%s", v), 1)
|
||||
} else {
|
||||
s.Sql = strings.Replace(s.Sql, util.PartitionPlaceholder, fmt.Sprintf(",%s", v), 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SqlBuilder[T]) DeletePlaceholderSymbol() {
|
||||
s.Sql = strings.Replace(s.Sql, util.SelectPlaceholder, "", -1)
|
||||
|
|
|
@ -76,11 +76,12 @@ func TestMain(m *testing.M) {
|
|||
left join tinvestment_type t3 on t1.industry_category_id = t3.autoseq and t3.del = 0
|
||||
left join tpreliminary_procedures t6 on t1.autoseq = t6.project_id
|
||||
where t1.del = 0 @c @c @c @c @c
|
||||
group by t1.autoseq`
|
||||
@g`
|
||||
sqlb.Sql = slqs
|
||||
if company_id != 0 {
|
||||
sqlb.Conditions("t2.autoseq = ?", company_id)
|
||||
}
|
||||
sqlb.Groups("group by t1.autoseq")
|
||||
fmt.Println(sqlb)
|
||||
var err error
|
||||
page := Page{PageIndex: 2, PageSize: 10}
|
||||
|
|
Loading…
Reference in New Issue