From babbddff1ca2ab497f2c4cad2fcf3ead8f5e4dbf Mon Sep 17 00:00:00 2001 From: John Date: Fri, 20 Apr 2018 23:37:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BORM=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- g/database/gdb/gdb_transaction.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/g/database/gdb/gdb_transaction.go b/g/database/gdb/gdb_transaction.go index 12a8d5153..315242ca7 100644 --- a/g/database/gdb/gdb_transaction.go +++ b/g/database/gdb/gdb_transaction.go @@ -50,6 +50,24 @@ func (tx *Tx) Exec(query string, args ...interface{}) (sql.Result, error) { return r, err } +// (事务)数据表查询,其中tables可以是多个联表查询语句,这种查询方式较复杂,建议使用链式操作 +func (tx *Tx) Select(tables, fields string, condition interface{}, groupBy, orderBy string, first, limit int, args ... interface{}) (List, error) { + s := fmt.Sprintf("SELECT %s FROM %s ", fields, tables) + if condition != nil { + s += fmt.Sprintf("WHERE %s ", tx.db.formatCondition(condition)) + } + if len(groupBy) > 0 { + s += fmt.Sprintf("GROUP BY %s ", groupBy) + } + if len(orderBy) > 0 { + s += fmt.Sprintf("ORDER BY %s ", orderBy) + } + if limit > 0 { + s += fmt.Sprintf("LIMIT %d,%d ", first, limit) + } + return tx.GetAll(s, args ... ) +} + // (事务)数据库查询,获取查询结果集,以列表结构返回 func (tx *Tx) GetAll(query string, args ...interface{}) (List, error) { // 执行sql