6 Star 1 Fork 1

深圳市格麦信息技术有限公司/GO 应用开发框架

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
query.go 1.11 KB
一键复制 编辑 原始数据 按行查看 历史
deiva 提交于 2026-01-04 14:39 +08:00 . #
package db
import (
"database/sql"
"fmt"
"strings"
"gitee.com/sosotec/gwork"
)
func queryDataRows(model interface{}, cols string, where map[string]interface{}, size int, idx int) (
table *tableInfo,
rows *sql.Rows,
values []sql.RawBytes,
scans []interface{},
columns []string,
) {
//获取表信息
table = getTableInfo(model)
query := []string{}
//如果字段为空
if cols == "" {
cols = "*"
}
//如果有数量
if idx > 1 && size > 0 {
query = append(query, fmt.Sprintf("OFFSET %d LIMIT %d", size*(idx-1), size))
} else if size > 0 {
query = append(query, fmt.Sprintf("LIMIT %d", size))
}
//组装SQL说句
sqlText := fmt.Sprintf(
"SELECT %s FROM %s %s",
cols,
table.TableName,
strings.Join(query, " "),
)
fmt.Println(sqlText)
// Execute the query
rows, err := gwork.MySqlDb.Query(sqlText)
if err != nil {
panic(err.Error())
}
// Get column names
columns, _ = rows.Columns()
fields := len(columns)
// Make a slice for the values
values = make([]sql.RawBytes, fields)
scans = make([]interface{}, fields)
for i := range values {
scans[i] = &values[i]
}
//返回
return
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/sosotec/gwork.git
git@gitee.com:sosotec/gwork.git
sosotec
gwork
GO 应用开发框架
v1.0.4

搜索帮助