utils.go 602 字节
Newer Older
Y
Your Name 已提交
1
package console_sqlite3
E
eoLinker API Management 已提交
2 3 4 5 6 7

import (
	SQL "database/sql"
	"fmt"
)

Y
Your Name 已提交
8
func getCountSQL(db *SQL.DB,sql string, args ...interface{}) int {
E
eoLinker API Management 已提交
9 10
	var count int
	countSQL := fmt.Sprintf("SELECT COUNT(*) FROM (%s) A", sql)
Y
Your Name 已提交
11
	err := db.QueryRow(countSQL, args...).Scan(&count)
E
eoLinker API Management 已提交
12
	if err != nil {
Y
Your Name 已提交
13
		return 0
E
eoLinker API Management 已提交
14 15 16 17
	}
	return count
}

Y
Your Name 已提交
18
func getPageSQL(db *SQL.DB,sql string, orderBy, orderType string, page, pageSize int, args ...interface{}) (*SQL.Rows, error) {
E
eoLinker API Management 已提交
19 20
	pageSQL := fmt.Sprintf("%s ORDER BY %s %s LIMIT ?,?", sql, orderBy, orderType)
	args = append(args, (page-1)*pageSize, pageSize)
Y
Your Name 已提交
21
	return db.Query(pageSQL, args...)
E
eoLinker API Management 已提交
22
}