Skip to content

Commit

Permalink
s
Browse files Browse the repository at this point in the history
  • Loading branch information
sim-wangyan committed Jul 9, 2024
1 parent 776ae82 commit e7c13ed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ or build condition sql for some orm framework, like [xorm](https://github.com/go
cb.Gte("price", catRo.Price).OR().Eq("is_sold", catRo.IsSold))
})

vs, dataSql, countSql, _ := builder.Build().Sql()
countSql, dataSql, vs, _ := builder.Build().Sql()
var catList []Cat
err = Db.Select(&catList, dataSql, vs...)

Expand Down Expand Up @@ -120,7 +120,7 @@ func main() {
builder.Paged(func(pb *PageBuilder) {
pb.Page(1).Rows(10).IgnoreTotalRows()
})
vs, dataSql, countSql, _ := builder.Build().Sql()
countSql, dataSql, vs, _ := builder.Build().SqlOfPage()
// ....

//dataSql: SELECT * FROM t_cat WHERE id > ? AND name LIKE ? AND weight <> 0 AND (price >= ? OR age >= ?) OR (price < ?)
Expand Down
25 changes: 16 additions & 9 deletions to_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,22 @@ func (built *Built) countBuilder() *strings.Builder {
return sbCount
}

func (built *Built) SqlOfPage() (string, string, []interface{}, map[string]string) {
vs := []interface{}{}
km := make(map[string]string) //nil for sub From builder,
dataSql, kmp := built.sqlData(&vs, km)
countSql := built.sqlCount()

return countSql, dataSql, vs, kmp
}

func (built *Built) SqlOfSelect() (string, []interface{}, map[string]string) {
vs := []interface{}{}
km := make(map[string]string) //nil for sub From builder,
dataSql, kmp := built.sqlData(&vs, km)
return dataSql, vs, kmp
}

func (built *Built) SqlOfUpdate() (string, []interface{}) {
vs := []interface{}{}
km := make(map[string]string) //nil for sub From builder,
Expand Down Expand Up @@ -316,15 +332,6 @@ func (built *Built) sqlWhere(bp *strings.Builder) {
bp.WriteString(WHERE)
}

func (built *Built) Sql() ([]interface{}, string, string, map[string]string) {
vs := []interface{}{}
km := make(map[string]string) //nil for sub From builder,
dataSql, kmp := built.sqlData(&vs, km)
countSql := built.sqlCount()

return vs, dataSql, countSql, kmp
}

func (built *Built) sqlData(vs *[]interface{}, km map[string]string) (string, map[string]string) {
sb := strings.Builder{}
built.toResultKeySql(&sb, km)
Expand Down

0 comments on commit e7c13ed

Please sign in to comment.