Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README_en.md
  • Loading branch information
tobycroft committed Sep 19, 2022
2 parents ccea085 + 405cdf1 commit e08a25d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- 所有的更新/Bug修复完全来自于当前正在编写的商业项目,不可能出现更新后不管的情况
- 支持复杂Where/OrWhere条件下的and/or条件查询(复杂环境下极好用!)
- 更加好用的Paginator行数,高效不出错
- CountGroup使用GroupBy的时候返回正确的行数

## 本项目目的

Expand Down
8 changes: 6 additions & 2 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

~~~
██████╗ ██████╗ ██████╗ ██████╗ ███████╗███████╗ ██████╗ ██████╗ ██████╗
██╔════╝ ██╔═══██╗██╔══██╗██╔═══██╗██╔════╝██[]()╔════╝ ██╔══██╗██╔══██╗██╔═══██╗
██╔════╝ ██╔═══██╗██╔══██╗██╔═══██╗██╔════╝██╔════╝ ██╔══██╗██╔══██╗██╔═══██╗
██║ ███╗██║ ██║██████╔╝██║ ██║███████╗█████╗█████╗██████╔╝██████╔╝██║ ██║
██║ ██║██║ ██║██╔══██╗██║ ██║╚════██║██╔══╝╚════╝██╔═══╝ ██╔══██╗██║ ██║
╚██████╔╝╚██████╔╝██║ ██║╚██████╔╝███████║███████╗ ██║ ██║ ██║╚██████╔╝
Expand All @@ -29,6 +29,9 @@
- 100% compatible with original function
- Dealing PR & Bug fix much more sooner
- All function has been tested and verified by commercial projects
- Support complexity and/or sql in Where/OrWhere function
- Paginator is now able to return the correct TOTAL number
- Add CountGroup to return correct row count from sql sentence

## Purpose of this project

Expand All @@ -39,7 +42,8 @@
## Bug Fix

- Dirty Read under concurrency circumstances(this will be only and easily triggered by using *db mode)
- Paginate fix[]()ed, this function finally come back to life, new "Paginator" function make it much more easier to use
- Paginate fixed, this function finally come back to life, new "Paginator" function make it much more easier to use
- Fix the row_count(Total in Paginator mode) when using GroupBy function

## Docs and Demos(Wiki)

Expand Down
17 changes: 17 additions & 0 deletions orm_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ func (dba *Orm) Count(args ...string) (int64, error) {
return t.New(count).Int64(), err
}

// CountNested : select count (select count.....)
func (dba *Orm) CountGroup(count_fileds ...string) (count int64, err error) {
dba.fields = []string{"count(distinct " + dba.group + ") as count"}

// 构建sql
sqls, args, err_sql := dba.BuildSql()
if err != nil {
err = err_sql
return
}
total_number, err := dba.Query(`SELECT count(0) as count from(`+sqls+`) as counts`, args...)
if err != nil {
return 0, err
}
return t.New(total_number[0]["count"]).Int64(), err
}

// Sum : select sum field
func (dba *Orm) Sum(sum string) (interface{}, error) {
return dba._unionBuild("sum", sum)
Expand Down

0 comments on commit e08a25d

Please sign in to comment.