Browse Source

添加分组功能

master v0.9.0
zhenghaorong 2 years ago
parent
commit
8a4277f0eb
3 changed files with 20 additions and 20 deletions
  1. +8
    -8
      chain.go
  2. +6
    -6
      db.go
  3. +6
    -6
      transaction_chain.go

+ 8
- 8
chain.go View File

@ -24,7 +24,7 @@ type Query struct {
data []string
value []interface{}
orderby string
gruopby string
groupby string
page int
page_size int
stmt *sql.Stmt
@ -93,8 +93,8 @@ func (this *Query) Orderby(orderby string) *Query {
this.orderby = orderby
return this
}
func (this *Query) Gruopby(gruopby string) *Query {
this.gruopby = gruopby
func (this *Query) Groupby(groupby string) *Query {
this.groupby = groupby
return this
}
func (this *Query) Where(where string) *Query {
@ -148,7 +148,7 @@ func (this *Query) Clean() *Query {
this.data = this.data[0:0]
this.value = this.value[0:0]
this.orderby = ""
this.gruopby = ""
this.groupby = ""
this.page = 0
this.page_size = 0
return this
@ -205,8 +205,8 @@ func (this *Query) QueryStmt() error {
sql = helper.StringJoin(sql, strings.Join(this.where_or, " or "))
}
}
if this.gruopby != "" {
sql = helper.StringJoin(sql, " gruop by ", this.gruopby)
if this.groupby != "" {
sql = helper.StringJoin(sql, " group by ", this.groupby)
}
if this.orderby != "" {
@ -400,7 +400,7 @@ func (this *Query) DeleteStmt() error {
func (this *Query) Select() ([]map[string]string, error) {
_, rows, err := FetchRows(this.dbname, this.table, this.alias, this.title, this.join,
this.where, this.where_or, this.value, this.orderby, this.gruopby, this.page, this.page_size, this.debug)
this.where, this.where_or, this.value, this.orderby, this.groupby, this.page, this.page_size, this.debug)
return rows, err
}
@ -431,7 +431,7 @@ func (this *Query) List() ([]map[string]string, error) {
func (this *Query) Find() (map[string]string, error) {
_, row, err := GetRow(this.dbname, this.table, this.alias, this.title, this.join,
this.where, this.where_or, this.value, this.orderby, this.gruopby, this.debug)
this.where, this.where_or, this.value, this.orderby, this.groupby, this.debug)
return row, err
}


+ 6
- 6
db.go View File

@ -284,7 +284,7 @@ func GetData(dbName, table string, title string, where map[string]string, limit
* @param dbName 数据表名
* @param title 查询字段名
*/
func GetRow(dbName, table_name, alias string, titles string, join [][]string, where, where_or []string, valueList []interface{}, orderby, gruopby string, debug bool) (int, map[string]string, error) {
func GetRow(dbName, table_name, alias string, titles string, join [][]string, where, where_or []string, valueList []interface{}, orderby, groupby string, debug bool) (int, map[string]string, error) {
var count int = 0
info := make(map[string]string)
@ -334,8 +334,8 @@ func GetRow(dbName, table_name, alias string, titles string, join [][]string, wh
sql_str = helper.StringJoin(sql_str, strings.Join(where_or, " or "))
}
}
if gruopby != "" {
sql_str = helper.StringJoin(sql_str, " gruop by ", gruopby)
if groupby != "" {
sql_str = helper.StringJoin(sql_str, " group by ", groupby)
}
if orderby != "" {
sql_str = helper.StringJoin(sql_str, " order by ", orderby)
@ -424,7 +424,7 @@ func GetRow(dbName, table_name, alias string, titles string, join [][]string, wh
* @param dbName 数据表名
* @param title 查询字段名
*/
func FetchRows(dbName, table_name, alias string, titles string, join [][]string, where, where_or []string, valueList []interface{}, orderby, gruopby string, page int, page_size int, debug bool) (int, []map[string]string, error) {
func FetchRows(dbName, table_name, alias string, titles string, join [][]string, where, where_or []string, valueList []interface{}, orderby, groupby string, page int, page_size int, debug bool) (int, []map[string]string, error) {
var count int = 0
list := make([]map[string]string, 0)
@ -475,8 +475,8 @@ func FetchRows(dbName, table_name, alias string, titles string, join [][]string,
sql_str = helper.StringJoin(sql_str, strings.Join(where_or, " or "))
}
}
if gruopby != "" {
sql_str = helper.StringJoin(sql_str, " gruop by ", gruopby)
if groupby != "" {
sql_str = helper.StringJoin(sql_str, " group by ", groupby)
}
if orderby != "" {
sql_str = helper.StringJoin(sql_str, " order by ", orderby)


+ 6
- 6
transaction_chain.go View File

@ -24,7 +24,7 @@ type TxQuery struct {
data []string
value []interface{}
orderby string
gruopby string
groupby string
page int
page_size int
stmt *sql.Stmt
@ -94,8 +94,8 @@ func (this *TxQuery) Orderby(orderby string) *TxQuery {
this.orderby = orderby
return this
}
func (this *TxQuery) Gruopby(gruopby string) *TxQuery {
this.gruopby = gruopby
func (this *TxQuery) Groupby(groupby string) *TxQuery {
this.groupby = groupby
return this
}
@ -149,7 +149,7 @@ func (this *TxQuery) Clean() *TxQuery {
this.data = this.data[0:0]
this.value = this.value[0:0]
this.orderby = ""
this.gruopby = ""
this.groupby = ""
this.page = 0
this.page_size = 0
return this
@ -204,8 +204,8 @@ func (this *TxQuery) QueryStmt() error {
sql = helper.StringJoin(sql, strings.Join(this.where_or, " or "))
}
}
if this.gruopby != "" {
sql = helper.StringJoin(sql, " gruop by ", this.gruopby)
if this.groupby != "" {
sql = helper.StringJoin(sql, " group by ", this.groupby)
}
if this.orderby != "" {


Loading…
Cancel
Save